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.
This commit is contained in:
parent
d85e3dbf28
commit
d974321854
1 changed files with 8 additions and 4 deletions
12
tango.py
12
tango.py
|
|
@ -64,9 +64,11 @@ class setup:
|
||||||
print e.headers
|
print e.headers
|
||||||
print "shortenURL() failed with a " + str(e.code) + " error code."
|
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
|
queryURL = base_url
|
||||||
questionMarkUsed = False
|
questionMarkUsed = False
|
||||||
|
if kwargs.has_key("questionMarkUsed") is True:
|
||||||
|
questionMarkUsed = True
|
||||||
for param in params:
|
for param in params:
|
||||||
if params[param] is not None:
|
if params[param] is not None:
|
||||||
queryURL += (("&" if questionMarkUsed is True else "?") + param + "=" + params[param])
|
queryURL += (("&" if questionMarkUsed is True else "?") + param + "=" + params[param])
|
||||||
|
|
@ -531,10 +533,12 @@ class setup:
|
||||||
else:
|
else:
|
||||||
print "getBlockedIDs() requires you to be authenticated."
|
print "getBlockedIDs() requires you to be authenticated."
|
||||||
|
|
||||||
def searchTwitter(self, search_query, optional_page = "1"):
|
def searchTwitter(self, search_query, **kwargs):
|
||||||
params = urllib.urlencode({'q': search_query, 'rpp': optional_page}) # Doesn't hurt to do pages this way. *shrug*
|
baseURL = "http://search.twitter.com/search.json?" + urllib.urlencode({"q": search_query})
|
||||||
|
searchURL = self.constructApiURL(baseURL, kwargs, questionMarkUsed=True)
|
||||||
|
print searchURL
|
||||||
try:
|
try:
|
||||||
return simplejson.load(urllib2.urlopen("http://search.twitter.com/search.json", params))
|
return simplejson.load(urllib2.urlopen(searchURL))
|
||||||
except HTTPError, e:
|
except HTTPError, e:
|
||||||
if self.debug is True:
|
if self.debug is True:
|
||||||
print e.headers
|
print e.headers
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue