From 90d7e5ffb00b70e8805834161f8ce1344a116b15 Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Mon, 8 Jun 2009 02:54:53 -0400 Subject: [PATCH] The final API method, Saved Searches. Fixed an issue with the Direct Message function where urllib.urlencode wasn't formed properly; only thing left for release is OAuth. --- tango.py | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/tango.py b/tango.py index 9f0f760..dc9e674 100644 --- a/tango.py +++ b/tango.py @@ -216,7 +216,7 @@ class setup: if self.authenticated is True: if len(list(text)) < 140: try: - return self.opener.open("http://twitter.com/direct_messages/new.json", urllib.urlencode({"user": user, "text" text})) + return self.opener.open("http://twitter.com/direct_messages/new.json", urllib.urlencode({"user": user, "text": text})) except HTTPError, e: if self.debug is True: print e.headers @@ -579,6 +579,50 @@ class setup: print e.headers print "getWeeklyTrends() failed with a " + str(e.code) + " error code." + def getSavedSearches(self): + if self.authenticated is True: + try: + return simplejson.load(self.opener.open("http://twitter.com/saved_searches.json")) + except HTTPError, e: + if self.debug is True: + print e.headers + print "getSavedSearches() failed with a " + str(e.code) + " error code." + else: + print "getSavedSearches() requires you to be authenticated." + + def showSavedSearch(self, id): + if self.authenticated is True: + try: + return simplejson.load(self.opener.open("http://twitter.com/saved_searches/show/" + id + ".json")) + except HTTPError, e: + if self.debug is True: + print e.headers + print "showSavedSearch() failed with a " + str(e.code) + " error code." + else: + print "showSavedSearch() requires you to be authenticated." + + def createSavedSearch(self, query): + if self.authenticated is True: + try: + return simplejson.load(self.opener.open("http://twitter.com/saved_searches/create.json?query=" + query, "")) + except HTTPError, e: + if self.debug is True: + print e.headers + print "createSavedSearch() failed with a " + str(e.code) + " error code." + else: + print "createSavedSearch() requires you to be authenticated." + + def destroySavedSearch(self, id): + if self.authenticated is True: + try: + return simplejson.load(self.opener.open("http://twitter.com/saved_searches/destroy/" + id + ".json", "")) + except HTTPError, e: + if self.debug is True: + print e.headers + print "destroySavedSearch() failed with a " + str(e.code) + " error code." + else: + print "destroySavedSearch() requires you to be authenticated." + # The following methods are apart from the other Account methods, because they rely on a whole multipart-data posting function set. def updateProfileBackgroundImage(self, filename, tile="true"): if self.authenticated is True: