Sketched out a basic method for oauth to work in my app...

This commit is contained in:
Anna 2010-05-20 16:51:51 -04:00
parent e32209bf2b
commit f70e76acc2
3 changed files with 40 additions and 13 deletions

View file

@ -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