Aiming to remove need for httplib2, but sadly this commit is broken.
This commit is contained in:
parent
10c32e427c
commit
1887280855
1 changed files with 100 additions and 105 deletions
21
tango.py
21
tango.py
|
|
@ -11,20 +11,11 @@ try:
|
|||
except:
|
||||
print "Tango requires the simplejson library to work. http://www.undefined.org/python/"
|
||||
|
||||
# Should really deprecate httplib2 at some point...
|
||||
try:
|
||||
import httplib2
|
||||
except:
|
||||
print "Tango requires httplib2 for authentication purposes. http://code.google.com/p/httplib2/"
|
||||
|
||||
try:
|
||||
import oauth
|
||||
except:
|
||||
print "Tango requires oauth for authentication purposes. http://oauth.googlecode.com/svn/code/python/oauth/oauth.py"
|
||||
|
||||
|
||||
# Need to support URL shortening
|
||||
|
||||
class setup:
|
||||
def __init__(self, authtype = "OAuth", username = None, password = None, oauth_keys = None):
|
||||
self.authtype = authtype
|
||||
|
|
@ -32,12 +23,15 @@ class setup:
|
|||
self.username = username
|
||||
self.password = password
|
||||
self.oauth_keys = oauth_keys
|
||||
self.http = httplib2.Http() # For Basic Auth...
|
||||
self.opener = None
|
||||
if self.username is not None and self.password is not None:
|
||||
if self.authtype == "OAuth":
|
||||
pass
|
||||
elif self.authtype == "Basic":
|
||||
self.http.add_credentials(self.username, self.password)
|
||||
self.auth_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
|
||||
self.auth_manager.add_password(None, "http://twitter.com/account/verify_credentials.json", self.username, self.password)
|
||||
self.handler = urllib2.HTTPBasicAuthHandler(self.auth_manager)
|
||||
self.opener = urllib2.build_opener(self.handler)
|
||||
self.authenticated = True
|
||||
else:
|
||||
pass
|
||||
|
|
@ -84,10 +78,11 @@ class setup:
|
|||
print "getUserMentions() requires you to be authenticated."
|
||||
pass
|
||||
|
||||
def updateStatus(self, status = None, in_reply_to_status_id = None):
|
||||
def updateStatus(self, status, in_reply_to_status_id = ""):
|
||||
if self.authenticated is True:
|
||||
if self.authtype == "Basic":
|
||||
self.http.request("http://twitter.com/statuses/update.json", "POST", urllib.urlencode({"status": status}, {"in_reply_to_status_id": in_reply_to_status_id}))
|
||||
self.opener.open("http://twitter.com/statuses/update.json" + urllib.urlencode({"status": status}, {"in_reply_to_status_id": in_reply_to_status_id}))
|
||||
print self.opener.open("http://twitter.com/statuses/update.json" + urllib.urlencode({"status": status}, {"in_reply_to_status_id": in_reply_to_status_id})).read()
|
||||
else:
|
||||
print "Sorry, OAuth support is still forthcoming. Feel free to help out on this front!"
|
||||
pass
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue