Sketched out a basic method for oauth to work in my app...
This commit is contained in:
parent
e32209bf2b
commit
f70e76acc2
|
@ -9,8 +9,8 @@ from urllib2 import HTTPError,URLError
|
||||||
import avcache
|
import avcache
|
||||||
|
|
||||||
# These are the global constants for the twitter oauth entry for our app
|
# These are the global constants for the twitter oauth entry for our app
|
||||||
CONSUMER_KEY = jGu64TPCUtyLZKyWyMJldQ
|
CONSUMER_KEY = 'jGu64TPCUtyLZKyWyMJldQ'
|
||||||
CONSUMER_SECRET = lTRrTyvzRfJab5HsAe16zkV8tqFVRp0k0cTfHL0l4GE
|
CONSUMER_SECRET = 'lTRrTyvzRfJab5HsAe16zkV8tqFVRp0k0cTfHL0l4GE'
|
||||||
|
|
||||||
|
|
||||||
class CustomApi(OAuthApi):
|
class CustomApi(OAuthApi):
|
||||||
|
@ -20,11 +20,13 @@ class CustomApi(OAuthApi):
|
||||||
instantiated
|
instantiated
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def __init__(self, access_token):
|
def __init__(self, username, access_token):
|
||||||
OAuthApi.__init__(self, CONSUMER_KEY, CONSUMER_SECRET, access_token)
|
OAuthApi.__init__(self, CONSUMER_KEY, CONSUMER_SECRET, access_token)
|
||||||
self.lock = RLock()
|
self.lock = RLock()
|
||||||
self.sig_proxy = SigProxy()
|
self.sig_proxy = SigProxy()
|
||||||
|
|
||||||
|
self.username = username
|
||||||
|
|
||||||
thread = GetUserLists(api=self)
|
thread = GetUserLists(api=self)
|
||||||
thread.sig_proxy.connect('lists-ready', self.on_lists_ready)
|
thread.sig_proxy.connect('lists-ready', self.on_lists_ready)
|
||||||
thread.start()
|
thread.start()
|
||||||
|
@ -463,5 +465,15 @@ def dms_to_statuses(direct_messages):
|
||||||
return statuses
|
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()
|
||||||
|
|
21
hrafn.py
21
hrafn.py
|
@ -59,6 +59,9 @@ class Hrafn():
|
||||||
db_file = os.path.expanduser(config.get('global', 'dbfile'))
|
db_file = os.path.expanduser(config.get('global', 'dbfile'))
|
||||||
self.db = shelve.open(db_file)
|
self.db = shelve.open(db_file)
|
||||||
|
|
||||||
|
if not self.db.has_key('tokens'):
|
||||||
|
self.db['tokens'] = {}
|
||||||
|
|
||||||
if not self.db.has_key('active_page'):
|
if not self.db.has_key('active_page'):
|
||||||
self.db['active_page'] = 0
|
self.db['active_page'] = 0
|
||||||
|
|
||||||
|
@ -67,10 +70,10 @@ class Hrafn():
|
||||||
|
|
||||||
# Now set up the accounts and their corresponding APIs
|
# Now set up the accounts and their corresponding APIs
|
||||||
self.accounts = {}
|
self.accounts = {}
|
||||||
for item in config.sections():
|
for token in self.db['tokens']:
|
||||||
if (re.match(r'account', item)):
|
api = CustomApi(token)
|
||||||
username = config.get(item, 'username')
|
username = api.username
|
||||||
self.accounts[username] = apithreads.get_api(username=username, password=config.get(item, 'password'))
|
self.accounts[username] = api
|
||||||
self.accounts[username].sig_proxy.connect('lists-ready', self.on_lists_ready)
|
self.accounts[username].sig_proxy.connect('lists-ready', self.on_lists_ready)
|
||||||
|
|
||||||
if not self.db.has_key('active_user'):
|
if not self.db.has_key('active_user'):
|
||||||
|
@ -547,6 +550,16 @@ class Hrafn():
|
||||||
print 'debug: thread: ' + thread.name
|
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
|
### end class Hrafn
|
||||||
|
|
||||||
|
|
|
@ -14,9 +14,11 @@ __author__ = "Hameedullah Khan <hameed@hameedkhan.net>"
|
||||||
__version__ = "0.2"
|
__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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user