]> git.parisson.com Git - deefuzzer.git/commitdiff
add new twitter oauth methods, update doc
authorGuillaume Pellerin <yomguy@parisson.com>
Thu, 16 Dec 2010 00:24:03 +0000 (00:24 +0000)
committerGuillaume Pellerin <yomguy@parisson.com>
Thu, 16 Dec 2010 00:24:03 +0000 (00:24 +0000)
INSTALL
README
deefuzzer.py
example/myfuzz.xml
tools/get_access_token.py [new file with mode: 0644]
tools/station.py
tools/twitt.py

diff --git a/INSTALL b/INSTALL
index 3341d5539a0c0e7a14e60466fbbcf75b18f52103..a3664197788c69973d8e2e01aa0ecd2dfe921c0d 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 #
-# Copyright (c) 2007-2009 Guillaume Pellerin <pellerin@parisson.com>
+# Copyright (c) 2007-2010 Guillaume Pellerin <pellerin@parisson.com>
 # All rights reserved.
 #
 # This software is licensed as described in the file COPYING, which
@@ -9,24 +9,62 @@
 #
 # Author: Guillaume Pellerin <pellerin@parisson.com>
 
- depends:  python, python-dev, python-xml, python-shout | shout-python, libshout3,
+
+Dependencies
+=============
+
+depends:  python, python-dev, python-xml, python-shout | shout-python, libshout3,
            libshout3-dev, python-mutagen
 
- provides:  shout-python
+provides:  shout-python | python-shout, python-tinyurl
+
+optional: python-twitter, python-liblo | pyliblo (>= 0.26)
+
+recommends: icecast2
+
+
+Install
+=========
+
+To install the DeeFuzzer, go to the main deefuzzer app directory, for example::
+    
+    cd deefuzzer-0.4.3
+    
+and run the python installer::
+    
+    sudo python install.py
+
+For more informations, see http://svn.parisson.org/deefuzzer/
+
 
- optional: python-twitter, python-tinyurl, python-liblo | pyliblo (>= 0.26)
+Twitter (optional)
+=====================
 
- recommends: icecast2
+To get track twitting, please install python-twitter, python-oauth2 and all their dependencies.
+As Twitter now requires oauth key system since 07/2010, you need to get your own access token key pair.
+Please run the dedicated script to do this::
+    
+    python tools/get_access_token.py
+    
+You will be invited to copy/paste an URL in your browser to get a pin code.
+Then copy/paste this code into the console and press ENTER.
+The script gives you a pair of keys : one access token key and one access token secret key.
 
-python-shout is included in the DeeFuzzer but needs to be compiled and installed
-if you don't install deefuzzer from its debian package with aptitude.
-As explained in shout-python/INSTALL, you just have to run this command :
+Change the <twitter> block options in your deefuzzer XML config file, giving the 2 keys. 
+For example::
+    
+    <twitter>
+            <mode>1</mode>
+            <key>85039615-H6yAtXXCx7NobF5W40FV0c8epGZsQGkE7MG6XRjD2</key>
+            <secret>A1YW3llB9H9qVbjH8zOQTOkMlhVqh2a7LnA9Lt0b6Gc</secret>
+            <tags>Music Groove</tags>
+    </twitter>
+    
+Your DeeFuzzer will now tweet the currently playing track and new tracks on your profile.
 
-  $ cd shout-python
-  $ sudo python setup.py install
 
-To install the DeeFuzzer (from the main deefuzzer directory) :
+OSC Control
+=============
 
-  $ sudo python install.py
+Working, but no doc yet. Please read the code :)
 
-For more informations, see http://svn.parisson.org/deefuzzer/
\ No newline at end of file
diff --git a/README b/README
index ff36bbdf428342e1f39782d46f65fe902935fbd9..d5baf323f781157d5c7d90e178d60b5d9d468990 100644 (file)
--- a/README
+++ b/README
@@ -49,11 +49,11 @@ Usage : deefuzzer CONFIGFILE
 
 where CONFIGFILE is the path for a XML config file. For example::
 
-$ deefuzzer example/myfuzz.xml
+    deefuzzer example/myfuzz.xml
 
 To make the deefuzzer act as a deamon, just play it in the background::
 
-$ deefuzzer example/myfuzz.xml &
+    deefuzzer example/myfuzz.xml &
 
 Note that you must edit the config file with right parameters before playing.
 You can find an example for a draft XML file in the directory "example/" of this
@@ -66,11 +66,11 @@ BE CAREFULL : at the moment, the multi-threaded implementation of deefuzzer inst
 avoids shutting down the streams with CTRL+C... You have to kill them manually,
 after a CTRL+Z, making this::
 
-$ kill -9 PROCESS_ID
+    kill -9 PROCESS_ID
 
 or::
 
-$ kill -9 `pgrep deefuzzer`
+    pkill -9 deefuzzer
 
 
 XML Configuration
@@ -89,31 +89,31 @@ set up in the config file (see example/myfuzz.xml again...).
 
 Next track::
 
-$ python tools/osc_next.py
+    python tools/osc_next.py
 
 Start twitting::
 
-$ python tools/osc_twitter_start.py
+    python tools/osc_twitter_start.py
 
 Stop twitting::
 
-$ python see tools/osc_twitter_stop.py
+    python see tools/osc_twitter_stop.py
 
 Start relaying::
 
-$ python tools/osc_relay_start.py
+    python tools/osc_relay_start.py
 
 Stop relaying::
 
-$ python see tools/osc_relay_stop.py
+    python see tools/osc_relay_stop.py
 
 Start jingling::
 
-$ python see tools/osc_jingles_start.py
+    python see tools/osc_jingles_start.py
 
 Stop jingling::
 
-$ python see tools/osc_jingles_stop.py
+    python see tools/osc_jingles_stop.py
 
 
 Author
index 84f5f7eed219edb5a445c5bfecdf4ac4402e2ba9..ae45fdc7aae4d248cf5828a397b0f186bde9f79c 100755 (executable)
@@ -45,7 +45,7 @@ import platform
 from threading import Thread
 from tools import *
 
-version = '0.4.3'
+version = '0.5.0'
 year = datetime.datetime.now().strftime("%Y")
 platform_system = platform.system()
 
index 872e5a7dee9b7cf1e3a7663da271f83ff270b477..ca32342105ea3fe747183a50820605b9f24a295d 100644 (file)
@@ -60,9 +60,9 @@
             <!-- If '1', deefuzzer will tweet #nowplaying, new tracks and other things to Twitter. 'O' does nothing. -->
             <mode>0</mode>
             <!-- Your twitter username -->
-            <user>my_twitter_user</user>
+            <key>your access token key</key>
             <!-- Your twitter password -->
-            <pass>my_twitter_password</pass>
+            <secret>your access token secret key</secret>
             <!-- These tags will be added to each twitter message -->
             <tags>bla bla</tags>
         </twitter>
diff --git a/tools/get_access_token.py b/tools/get_access_token.py
new file mode 100644 (file)
index 0000000..a614173
--- /dev/null
@@ -0,0 +1,90 @@
+#!/usr/bin/python2.4
+#
+# Copyright 2007 The Python-Twitter Developers
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+import os
+import sys
+
+# parse_qsl moved to urlparse module in v2.6
+try:
+  from urlparse import parse_qsl
+except:
+  from cgi import parse_qsl
+
+import oauth2 as oauth
+
+REQUEST_TOKEN_URL = 'https://api.twitter.com/oauth/request_token'
+ACCESS_TOKEN_URL  = 'https://api.twitter.com/oauth/access_token'
+AUTHORIZATION_URL = 'https://api.twitter.com/oauth/authorize'
+SIGNIN_URL        = 'https://api.twitter.com/oauth/authenticate'
+
+consumer_key    = 'ozs9cPS2ci6eYQzzMSTb4g'
+consumer_secret = '1kNEffHgGSXO2gMNTr8HRum5s2ofx3VQnJyfd0es'
+
+if consumer_key is None or consumer_secret is None:
+  print 'You need to edit this script and provide values for the'
+  print 'consumer_key and also consumer_secret.'
+  print ''
+  print 'The values you need come from Twitter - you need to register'
+  print 'as a developer your "application".  This is needed only until'
+  print 'Twitter finishes the idea they have of a way to allow open-source'
+  print 'based libraries to have a token that can be used to generate a'
+  print 'one-time use key that will allow the library to make the request'
+  print 'on your behalf.'
+  print ''
+  sys.exit(1)
+
+signature_method_hmac_sha1 = oauth.SignatureMethod_HMAC_SHA1()
+oauth_consumer             = oauth.Consumer(key=consumer_key, secret=consumer_secret)
+oauth_client               = oauth.Client(oauth_consumer)
+
+print 'Requesting temp token from Twitter'
+
+resp, content = oauth_client.request(REQUEST_TOKEN_URL, 'GET')
+
+if resp['status'] != '200':
+  print 'Invalid respond from Twitter requesting temp token: %s' % resp['status']
+else:
+  request_token = dict(parse_qsl(content))
+
+  print ''
+  print 'Please visit this Twitter page and retrieve the pincode to be used'
+  print 'in the next step to obtaining an Authentication Token:'
+  print ''
+  print '%s?oauth_token=%s' % (AUTHORIZATION_URL, request_token['oauth_token'])
+  print ''
+
+  pincode = raw_input('Pincode? ')
+
+  token = oauth.Token(request_token['oauth_token'], request_token['oauth_token_secret'])
+  token.set_verifier(pincode)
+
+  print ''
+  print 'Generating and signing request for an access token'
+  print ''
+
+  oauth_client  = oauth.Client(oauth_consumer, token)
+  resp, content = oauth_client.request(ACCESS_TOKEN_URL, method='POST', body='oauth_verifier=%s' % pincode)
+  access_token  = dict(parse_qsl(content))
+
+  if resp['status'] != '200':
+    print 'The request for a Token did not succeed: %s' % resp['status']
+    print access_token
+  else:
+    print 'Your Twitter Access Token key: %s' % access_token['oauth_token']
+    print '          Access Token secret: %s' % access_token['oauth_token_secret']
+    print ''
+
index e1a761a2c54baadc6c6cddfb82f7a8a544d78ea5..5859a5eace5bb856306e7dfb8e580ba2ad634df5 100644 (file)
@@ -144,8 +144,8 @@ class Station(Thread):
         self.twitter_mode = 0
         if 'twitter' in self.station:
             self.twitter_mode = int(self.station['twitter']['mode'])
-            self.twitter_user = self.station['twitter']['user']
-            self.twitter_pass = self.station['twitter']['pass']
+            self.twitter_key = self.station['twitter']['key']
+            self.twitter_secret = self.station['twitter']['secret']
             self.twitter_tags = self.station['twitter']['tags'].split(' ')
             if self.twitter_mode == 1:
                 self.twitter_callback('/twitter', [1])
@@ -212,7 +212,7 @@ class Station(Thread):
     def twitter_callback(self, path, value):
         value = value[0]
         import tinyurl
-        self.twitter = Twitter(self.twitter_user, self.twitter_pass)
+        self.twitter = Twitter(self.twitter_key, self.twitter_secret)
         self.twitter_mode = value
         message = "Received OSC message '%s' with arguments '%d'" % (path, value)
         self.m3u_tinyurl = tinyurl.create_one(self.channel.url + '/m3u/' + self.m3u.split(os.sep)[-1])
@@ -448,7 +448,7 @@ class Station(Thread):
         self.update_rss(self.current_media_obj, self.metadata_file, '')
         #self.channel.set_metadata({'song': self.song, 'charset': 'utf8',})
         self.update_rss(self.current_media_obj, self.rss_current_file, '(currently playing)')
-        self.logger.write_info('Deefuzzing on %s :  id = %s, name = %s' \
+        self.logger.write_info('DeeFuzzing on %s :  id = %s, name = %s' \
             % (self.short_name, self.id, self.current_media_obj[0].file_name))
         self.player.set_media(self.media)
         if self.player_mode == 0:
@@ -459,7 +459,7 @@ class Station(Thread):
     def update_twitter_current(self):
         artist_names = self.artist.split(' ')
         artist_tags = ' #'.join(list(set(artist_names)-set(['&', '-'])))
-        message = '♫ %s %s on #%s #%s' % (self.prefix, self.song, self.short_name, artist_tags)
+        message = '%s %s on #%s #%s' % (self.prefix, self.song, self.short_name, artist_tags)
         tags = '#' + ' #'.join(self.twitter_tags)
         message = message + ' ' + tags
         message = message[:107] + ' M3U : ' + self.m3u_tinyurl
index eec76e71cdb7e9034f6b8d42c6f987a4d0222689..9912f1bec85f722212f19925907dd608fc650e13 100644 (file)
 # Author: Guillaume Pellerin <yomguy@parisson.com>
 
 # Twitter DeeFuzzer keys
-TWITTER_CONSUMER_KEY = 'ozs9cPS2ci6eYQzzMSTb4g'
-TWITTER_CONSUMER_SECRET = '1kNEffHgGSXO2gMNTr8HRum5s2ofx3VQnJyfd0es'
+DEEFUZZER_CONSUMER_KEY = 'ozs9cPS2ci6eYQzzMSTb4g'
+DEEFUZZER_CONSUMER_SECRET = '1kNEffHgGSXO2gMNTr8HRum5s2ofx3VQnJyfd0es'
 
 
 class Twitter:
 
     def __init__(self, access_token_key, access_token_secret):
         import twitter
-        self.username = TWITTER_CONSUMER_KEY
-        self.password = TWITTER_CONSUMER_SECRET
+        self.consumer_key = DEEFUZZER_CONSUMER_KEY
+        self.consumer_secret = DEEFUZZER_CONSUMER_SECRET
         self.access_token_key = access_token_key
         self.access_token_secret = access_token_secret
-        self.api = twitter.Api(username=self.username,
-                               password=self.password,
+        self.api = twitter.Api(consumer_key=self.consumer_key,
+                               consumer_secret=self.consumer_secret,
                                access_token_key=self.access_token_key,
                                access_token_secret=self.access_token_secret)