From d9743218541463754e15cfb0ff2886e2df2da0a3 Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Thu, 18 Jun 2009 03:56:41 -0400 Subject: [PATCH] Finally got around to fixing the searchTwitter() function. It's now able to accept any and all parameters that correspond with Twitter's API; the final thing there should be allowing a user agent to be set, which still needs to be looked into. Shouldn't be too difficult. --- tango.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tango.py b/tango.py index 958f877..bf28d3d 100644 --- a/tango.py +++ b/tango.py @@ -64,9 +64,11 @@ class setup: print e.headers print "shortenURL() failed with a " + str(e.code) + " error code." - def constructApiURL(self, base_url, params): + def constructApiURL(self, base_url, params, **kwargs): queryURL = base_url questionMarkUsed = False + if kwargs.has_key("questionMarkUsed") is True: + questionMarkUsed = True for param in params: if params[param] is not None: queryURL += (("&" if questionMarkUsed is True else "?") + param + "=" + params[param]) @@ -531,10 +533,12 @@ class setup: else: print "getBlockedIDs() requires you to be authenticated." - def searchTwitter(self, search_query, optional_page = "1"): - params = urllib.urlencode({'q': search_query, 'rpp': optional_page}) # Doesn't hurt to do pages this way. *shrug* + def searchTwitter(self, search_query, **kwargs): + baseURL = "http://search.twitter.com/search.json?" + urllib.urlencode({"q": search_query}) + searchURL = self.constructApiURL(baseURL, kwargs, questionMarkUsed=True) + print searchURL try: - return simplejson.load(urllib2.urlopen("http://search.twitter.com/search.json", params)) + return simplejson.load(urllib2.urlopen(searchURL)) except HTTPError, e: if self.debug is True: print e.headers