From 0654705e9cebf971ac00e733c920e9548ae3adcd Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Thu, 16 Dec 2010 00:24:03 +0000 Subject: [PATCH] add new twitter oauth methods, update doc --- INSTALL | 64 ++++++++++++++++++++++------ README | 22 +++++----- deefuzzer.py | 2 +- example/myfuzz.xml | 4 +- tools/get_access_token.py | 90 +++++++++++++++++++++++++++++++++++++++ tools/station.py | 10 ++--- tools/twitt.py | 12 +++--- 7 files changed, 166 insertions(+), 38 deletions(-) create mode 100644 tools/get_access_token.py diff --git a/INSTALL b/INSTALL index 3341d55..a366419 100644 --- a/INSTALL +++ b/INSTALL @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (c) 2007-2009 Guillaume Pellerin +# Copyright (c) 2007-2010 Guillaume Pellerin # All rights reserved. # # This software is licensed as described in the file COPYING, which @@ -9,24 +9,62 @@ # # Author: Guillaume Pellerin - 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 block options in your deefuzzer XML config file, giving the 2 keys. +For example:: + + + 1 + 85039615-H6yAtXXCx7NobF5W40FV0c8epGZsQGkE7MG6XRjD2 + A1YW3llB9H9qVbjH8zOQTOkMlhVqh2a7LnA9Lt0b6Gc + Music Groove + + +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 ff36bbd..d5baf32 100644 --- 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 diff --git a/deefuzzer.py b/deefuzzer.py index 84f5f7e..ae45fdc 100755 --- a/deefuzzer.py +++ b/deefuzzer.py @@ -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() diff --git a/example/myfuzz.xml b/example/myfuzz.xml index 872e5a7..ca32342 100644 --- a/example/myfuzz.xml +++ b/example/myfuzz.xml @@ -60,9 +60,9 @@ 0 - my_twitter_user + your access token key - my_twitter_password + your access token secret key bla bla diff --git a/tools/get_access_token.py b/tools/get_access_token.py new file mode 100644 index 0000000..a614173 --- /dev/null +++ b/tools/get_access_token.py @@ -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 '' + diff --git a/tools/station.py b/tools/station.py index e1a761a..5859a5e 100644 --- a/tools/station.py +++ b/tools/station.py @@ -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 diff --git a/tools/twitt.py b/tools/twitt.py index eec76e7..9912f1b 100644 --- a/tools/twitt.py +++ b/tools/twitt.py @@ -37,20 +37,20 @@ # Author: Guillaume Pellerin # 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) -- 2.39.5