diff --git a/apithreads.py b/apithreads.py index e697e82..a739aa5 100644 --- a/apithreads.py +++ b/apithreads.py @@ -9,8 +9,8 @@ from urllib2 import HTTPError,URLError import avcache # These are the global constants for the twitter oauth entry for our app -CONSUMER_KEY = jGu64TPCUtyLZKyWyMJldQ -CONSUMER_SECRET = lTRrTyvzRfJab5HsAe16zkV8tqFVRp0k0cTfHL0l4GE +CONSUMER_KEY = 'jGu64TPCUtyLZKyWyMJldQ' +CONSUMER_SECRET = 'lTRrTyvzRfJab5HsAe16zkV8tqFVRp0k0cTfHL0l4GE' class CustomApi(OAuthApi): @@ -20,11 +20,13 @@ class CustomApi(OAuthApi): instantiated ''' - def __init__(self, access_token): + def __init__(self, username, access_token): OAuthApi.__init__(self, CONSUMER_KEY, CONSUMER_SECRET, access_token) self.lock = RLock() self.sig_proxy = SigProxy() + self.username = username + thread = GetUserLists(api=self) thread.sig_proxy.connect('lists-ready', self.on_lists_ready) thread.start() @@ -463,5 +465,15 @@ def dms_to_statuses(direct_messages): return statuses -def get_api(username, password): - +def get_access_token(): + auth_api = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET) + request_token = auth_api.getRequestToken() + authorization_url = auth_api.getAuthorizationURL(request_token) + + # Get authentication from url... buh? + + print 'debug: authorization_url: ' + authorization_url + exit(1) + + auth_api = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET, request_token) + return auth_api.getAccessToken() diff --git a/hrafn.py b/hrafn.py index 192ce4f..aaa6105 100755 --- a/hrafn.py +++ b/hrafn.py @@ -59,6 +59,9 @@ class Hrafn(): db_file = os.path.expanduser(config.get('global', 'dbfile')) self.db = shelve.open(db_file) + if not self.db.has_key('tokens'): + self.db['tokens'] = {} + if not self.db.has_key('active_page'): self.db['active_page'] = 0 @@ -67,12 +70,12 @@ class Hrafn(): # Now set up the accounts and their corresponding APIs self.accounts = {} - for item in config.sections(): - if (re.match(r'account', item)): - username = config.get(item, 'username') - self.accounts[username] = apithreads.get_api(username=username, password=config.get(item, 'password')) - self.accounts[username].sig_proxy.connect('lists-ready', self.on_lists_ready) - + for token in self.db['tokens']: + api = CustomApi(token) + username = api.username + self.accounts[username] = api + self.accounts[username].sig_proxy.connect('lists-ready', self.on_lists_ready) + if not self.db.has_key('active_user'): self.db['active_user'] = self.accounts.keys()[0] @@ -547,6 +550,16 @@ class Hrafn(): print 'debug: thread: ' + thread.name + def on_file_add_account(self, widget): + token = apithreads.get_access_token() + api = apithreads.CustomApi(token) + username = api.username + + if not self.accounts.has_key(username): + tokens = self.db['tokens'] + tokens.append(token) + self.db['tokens'] = tokens + self.accounts['username'] = api ### end class Hrafn diff --git a/oauthtwitter.py b/oauthtwitter.py index e33f201..a43b8dc 100755 --- a/oauthtwitter.py +++ b/oauthtwitter.py @@ -14,9 +14,11 @@ __author__ = "Hameedullah Khan " __version__ = "0.2" -from twitter import Api, User +from twitter import Api +from twitter_pb2 import User -import simplejson, oauth +import simplejson +import oauth.oauth as oauth