From 4cf64e3f60d0571bcfada4ebc43b5e1b9daccc87 Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Mon, 1 Jun 2009 00:02:47 -0400 Subject: [PATCH] Added in methods for getting, creating, and destroying favorites --- tango.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tango.py b/tango.py index f147136..52e1529 100644 --- a/tango.py +++ b/tango.py @@ -267,6 +267,40 @@ class setup: # If they're not authenticated print "updateProfile() requires you to be authenticated." + def getFavorites(self, page = "1"): + if self.authenticated is True: + try: + favoritesTimeline = simplejson.load(self.opener.open("http://twitter.com/favorites.json?page=" + page)) + return self.createGenericTimeline(favoritesTimeline) + except HTTPError, e: + if self.debug: + print e.headers + print "getFavorites() failed with a " + e.code + " error code." + else: + print "getFavorites() requires you to be authenticated." + + def createFavorite(self, id): + if self.authenticated is True: + try: + self.opener.open("http://twitter.com/favorites/create/" + id + ".json", "") + except HTTPError, e: + if self.debug: + print e.headers + print "createFavorite() failed with a " + e.code + " error code." + else: + print "createFavorite() requires you to be authenticated." + + def destroyFavorite(self, id): + if self.authenticated is True: + try: + self.opener.open("http://twitter.com/favorites/destroy/" + id + ".json", "") + except HTTPError, e: + if self.debug: + print e.headers + print "destroyFavorite() failed with a " + e.code + " error code." + else: + print "destroyFavorite() requires you to be authenticated." + def getSearchTimeline(self, search_query, optional_page): params = urllib.urlencode({'q': search_query, 'rpp': optional_page}) # Doesn't hurt to do pages this way. *shrug* try: