Added more API support to getUserTimeline(); fixed issues with Tango not properly importing, started basic Auth shell

This commit is contained in:
Ryan McGrath 2009-05-08 02:37:39 -04:00
parent 0b29bfbbae
commit 79f14afba2

View file

@ -1,25 +1,37 @@
#!/usr/bin/python
""" """
Django-Twitter (Tango) utility functions. Huzzah. Django-Twitter (Tango) utility functions. Huzzah.
""" """
import simplejson, urllib, urllib2 import simplejson, urllib, urllib2, base64
# Need to support URL shortening
class tango: class tango:
def __init__(self, twitter_user): def __init__(self, authtype = None, username = None, password = None):
# Authenticate here? self.authtype = authtype
self.twitter_user = twitter_user self.username = username
self.password = password
# Forthcoming auth work below, now requires base64 shiz
if self.authtype == "OAuth":
pass
elif self.authtype == "Basic":
print "Basic Auth"
else:
pass
def getUserTimeline(self, **kwargs): def getUserTimeline(self, count = None, since_id = None, max_id = None, page = None):
# Needs full API support, when I'm not so damn tired. # Fairly close to full API support, need a few other methods.
userTimelineURL = "http://twitter.com/statuses/user_timeline/" + self.twitter_user + ".json" userTimelineURL = "http://twitter.com/statuses/user_timeline/" + self.username + ".json"
if kwargs["count"] is not None: if count is not None:
userTimelineURL += "?count=" + kwargs["count"] userTimelineURL += "?count=" + count
if kwargs["since_id"] is not None: if since_id is not None:
userTimelineURL += "?since_id=" + kwargs["since_id"] userTimelineURL += "?since_id=" + since_id
if kwargs["max_id"] is not None: if max_id is not None:
userTimelineURL += "?max_id=" + kwargs["max_id"] userTimelineURL += "?max_id=" + max_id
if kwargs["page"] is not None: if page is not None:
userTimelineURL += "?page=" + kwargs["page"] userTimelineURL += "?page=" + page
userTimeline = simplejson.load(urllib2.urlopen(userTimelineURL)) userTimeline = simplejson.load(urllib2.urlopen(userTimelineURL))
formattedTimeline = [] formattedTimeline = []
for tweet in userTimeline: for tweet in userTimeline: