Search API Methods, trending and regular search stuff. Cleaned up some more parts of the library.
This commit is contained in:
parent
402a2dddc0
commit
9e1159dd6f
1 changed files with 44 additions and 5 deletions
49
tango.py
49
tango.py
|
|
@ -5,12 +5,12 @@
|
||||||
Other Python Twitter libraries seem to have fallen a bit behind, and
|
Other Python Twitter libraries seem to have fallen a bit behind, and
|
||||||
Twitter's API has evolved a bit. Here's hoping this helps.
|
Twitter's API has evolved a bit. Here's hoping this helps.
|
||||||
|
|
||||||
TODO: Blocks API Wrapper, Direct Messages API Wrapper, Friendship API Wrapper, OAuth, Streaming API
|
TODO: Streaming API?
|
||||||
|
|
||||||
Questions, comments? ryan@venodesigns.net
|
Questions, comments? ryan@venodesigns.net
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import httplib, urllib, urllib2, mimetypes, mimetools, pprint
|
import httplib, urllib, urllib2, mimetypes, mimetools
|
||||||
|
|
||||||
from urllib2 import HTTPError
|
from urllib2 import HTTPError
|
||||||
|
|
||||||
|
|
@ -523,7 +523,7 @@ class setup:
|
||||||
else:
|
else:
|
||||||
print "getBlockedIDs() requires you to be authenticated."
|
print "getBlockedIDs() requires you to be authenticated."
|
||||||
|
|
||||||
def getSearchTimeline(self, search_query, optional_page):
|
def searchTwitter(self, search_query, optional_page):
|
||||||
params = urllib.urlencode({'q': search_query, 'rpp': optional_page}) # Doesn't hurt to do pages this way. *shrug*
|
params = urllib.urlencode({'q': search_query, 'rpp': optional_page}) # Doesn't hurt to do pages this way. *shrug*
|
||||||
try:
|
try:
|
||||||
return simplejson.load(urllib2.urlopen("http://search.twitter.com/search.json", params))
|
return simplejson.load(urllib2.urlopen("http://search.twitter.com/search.json", params))
|
||||||
|
|
@ -532,14 +532,53 @@ class setup:
|
||||||
print e.headers
|
print e.headers
|
||||||
print "getSearchTimeline() failed with a " + str(e.code) + " error code."
|
print "getSearchTimeline() failed with a " + str(e.code) + " error code."
|
||||||
|
|
||||||
def getCurrentTrends(self):
|
def getCurrentTrends(self, excludeHashTags = False):
|
||||||
|
apiURL = "http://search.twitter.com/trends/current.json"
|
||||||
|
if excludeHashTags is True:
|
||||||
|
apiURL += "?exclude=hashtags"
|
||||||
try:
|
try:
|
||||||
return simplejson.load(urllib.urlopen("http://search.twitter.com/trends.json"))
|
return simplejson.load(urllib.urlopen(apiURL))
|
||||||
except HTTPError, e:
|
except HTTPError, e:
|
||||||
if self.debug is True:
|
if self.debug is True:
|
||||||
print e.headers
|
print e.headers
|
||||||
print "getCurrentTrends() failed with a " + str(e.code) + " error code."
|
print "getCurrentTrends() failed with a " + str(e.code) + " error code."
|
||||||
|
|
||||||
|
def getDailyTrends(self, date = None, exclude = False):
|
||||||
|
apiURL = "http://search.twitter.com/trends/daily.json"
|
||||||
|
questionMarkUsed = False
|
||||||
|
if date is not None:
|
||||||
|
apiURL += "?date=" + date
|
||||||
|
questionMarkUsed = True
|
||||||
|
if exclude is True:
|
||||||
|
if questionMarkUsed is True:
|
||||||
|
apiURL += "&exclude=hashtags"
|
||||||
|
else:
|
||||||
|
apiURL += "?exclude=hashtags"
|
||||||
|
try:
|
||||||
|
return simplejson.load(urllib.urlopen(apiURL))
|
||||||
|
except HTTPError, e:
|
||||||
|
if self.debug is True:
|
||||||
|
print e.headers
|
||||||
|
print "getDailyTrends() failed with a " + str(e.code) + " error code."
|
||||||
|
|
||||||
|
def getWeeklyTrends(self, date = None, exclude = False):
|
||||||
|
apiURL = "http://search.twitter.com/trends/daily.json"
|
||||||
|
questionMarkUsed = False
|
||||||
|
if date is not None:
|
||||||
|
apiURL += "?date=" + date
|
||||||
|
questionMarkUsed = True
|
||||||
|
if exclude is True:
|
||||||
|
if questionMarkUsed is True:
|
||||||
|
apiURL += "&exclude=hashtags"
|
||||||
|
else:
|
||||||
|
apiURL += "?exclude=hashtags"
|
||||||
|
try:
|
||||||
|
return simplejson.load(urllib.urlopen(apiURL))
|
||||||
|
except HTTPError, e:
|
||||||
|
if self.debug is True:
|
||||||
|
print e.headers
|
||||||
|
print "getWeeklyTrends() failed with a " + str(e.code) + " error code."
|
||||||
|
|
||||||
# The following methods are apart from the other Account methods, because they rely on a whole multipart-data posting function set.
|
# 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"):
|
def updateProfileBackgroundImage(self, filename, tile="true"):
|
||||||
if self.authenticated is True:
|
if self.authenticated is True:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue