Added check for authentication in updateStatus(). Not sure why this was never there; ideally, I should replace all these is_autheticated calls at some point with a decorator. This commit also has a new TangoError Exception class, which updateStatus() will now raise. This should be spread throughout the library in the coming week, when I have a chance to hit these two issues. (Note: The Python 3 version of Tango will most likely incur a lag of a day or so this week, in terms of receiving updates. This will hopefully be made easier in the future...
This commit is contained in:
parent
716fe69e60
commit
4a910f3b80
1 changed files with 18 additions and 8 deletions
26
tango.py
26
tango.py
|
|
@ -24,6 +24,12 @@ try:
|
|||
except ImportError:
|
||||
print "Tango requires oauth for authentication purposes. http://oauth.googlecode.com/svn/code/python/oauth/oauth.py"
|
||||
|
||||
class TangoError(Exception):
|
||||
def __init__(self, msg):
|
||||
self.msg = msg
|
||||
def __str__(self):
|
||||
return repr(self.msg)
|
||||
|
||||
class setup:
|
||||
def __init__(self, authtype = "OAuth", username = None, password = None, oauth_keys = None, debug = False):
|
||||
self.authtype = authtype
|
||||
|
|
@ -154,14 +160,18 @@ class setup:
|
|||
print "Failed with a " + str(e.code) + " error code. Does this user hide/protect their updates? If so, you'll need to authenticate and be their friend to get their timeline."
|
||||
|
||||
def updateStatus(self, status, in_reply_to_status_id = None):
|
||||
if len(list(status)) > 140:
|
||||
print "This status message is over 140 characters, but we're gonna try it anyway. Might wanna watch this!"
|
||||
try:
|
||||
return simplejson.load(self.opener.open("http://twitter.com/statuses/update.json?", urllib.urlencode({"status": status, "in_reply_to_status_id": in_reply_to_status_id})))
|
||||
except HTTPError, e:
|
||||
if self.debug is True:
|
||||
print e.headers
|
||||
print "updateStatus() failed with a " + str(e.code) + " error code."
|
||||
if self.authenticated is True:
|
||||
if len(list(status)) > 140:
|
||||
print "This status message is over 140 characters, but we're gonna try it anyway. Might wanna watch this!"
|
||||
try:
|
||||
return simplejson.load(self.opener.open("http://twitter.com/statuses/update.json?", urllib.urlencode({"status": status, "in_reply_to_status_id": in_reply_to_status_id})))
|
||||
except HTTPError, e:
|
||||
if self.debug is True:
|
||||
print e.headers
|
||||
raise TangoError("updateStatus() failed with a " + str(e.code) + "error code.")
|
||||
#print "updateStatus() failed with a " + str(e.code) + " error code."
|
||||
else:
|
||||
raise TangoError("updateStatus() requires you to be authenticated.")
|
||||
|
||||
def destroyStatus(self, id):
|
||||
if self.authenticated is True:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue