Updating Trends API to reflect new endpoints.

This commit is contained in:
Ryan McGrath 2010-04-23 00:26:57 -04:00
parent ab2dd1e2f0
commit fc6b9e1362
2 changed files with 26 additions and 14 deletions

View file

@ -1342,16 +1342,18 @@ class setup:
except HTTPError, e:
raise TwythonError("getSearchTimeline() failed with a %s error code." % `e.code`, e.code)
def getCurrentTrends(self, excludeHashTags = False):
"""getCurrentTrends(excludeHashTags = False)
def getCurrentTrends(self, excludeHashTags = False, version = None):
"""getCurrentTrends(excludeHashTags = False, version = None)
Returns the current top 10 trending topics on Twitter. The response includes the time of the request, the name of each trending topic, and the query used
on Twitter Search results page for that topic.
Parameters:
excludeHashTags - Optional. Setting this equal to hashtags will remove all hashtags from the trends list.
version (number) - Optional. API version to request. Entire Twython class defaults to 1, but you can override on a function-by-function or class basis - (version=2), etc.
"""
apiURL = "http://search.twitter.com/trends/current.json"
version = version or self.apiVersion
apiURL = "http://api.twitter.com/%d/trends/current.json" % version
if excludeHashTags is True:
apiURL += "?exclude=hashtags"
try:
@ -1359,16 +1361,18 @@ class setup:
except HTTPError, e:
raise TwythonError("getCurrentTrends() failed with a %s error code." % `e.code`, e.code)
def getDailyTrends(self, date = None, exclude = False):
"""getDailyTrends(date = None, exclude = False)
def getDailyTrends(self, date = None, exclude = False, version = None):
"""getDailyTrends(date = None, exclude = False, version = None)
Returns the top 20 trending topics for each hour in a given day.
Parameters:
date - Optional. Permits specifying a start date for the report. The date should be formatted YYYY-MM-DD.
exclude - Optional. Setting this equal to hashtags will remove all hashtags from the trends list.
version (number) - Optional. API version to request. Entire Twython class defaults to 1, but you can override on a function-by-function or class basis - (version=2), etc.
"""
apiURL = "http://search.twitter.com/trends/daily.json"
version = version or self.apiVersion
apiURL = "http://api.twitter.com/%d/trends/daily.json" % version
questionMarkUsed = False
if date is not None:
apiURL += "?date=%s" % date
@ -1391,8 +1395,10 @@ class setup:
Parameters:
date - Optional. Permits specifying a start date for the report. The date should be formatted YYYY-MM-DD.
exclude - Optional. Setting this equal to hashtags will remove all hashtags from the trends list.
version (number) - Optional. API version to request. Entire Twython class defaults to 1, but you can override on a function-by-function or class basis - (version=2), etc.
"""
apiURL = "http://search.twitter.com/trends/daily.json"
version = version or self.apiVersion
apiURL = "http://api.twitter.com/%d/trends/daily.json" % version
questionMarkUsed = False
if date is not None:
apiURL += "?date=%s" % date

View file

@ -1342,16 +1342,18 @@ class setup:
except HTTPError as e:
raise TwythonError("getSearchTimeline() failed with a %s error code." % repr(e.code), e.code)
def getCurrentTrends(self, excludeHashTags = False):
"""getCurrentTrends(excludeHashTags = False)
def getCurrentTrends(self, excludeHashTags = False, version = None):
"""getCurrentTrends(excludeHashTags = False, version = None)
Returns the current top 10 trending topics on Twitter. The response includes the time of the request, the name of each trending topic, and the query used
on Twitter Search results page for that topic.
Parameters:
excludeHashTags - Optional. Setting this equal to hashtags will remove all hashtags from the trends list.
version (number) - Optional. API version to request. Entire Twython class defaults to 1, but you can override on a function-by-function or class basis - (version=2), etc.
"""
apiURL = "http://search.twitter.com/trends/current.json"
version = version or self.apiVersion
apiURL = "http://api.twitter.com/%d/trends/current.json" % version
if excludeHashTags is True:
apiURL += "?exclude=hashtags"
try:
@ -1359,16 +1361,18 @@ class setup:
except HTTPError as e:
raise TwythonError("getCurrentTrends() failed with a %s error code." % repr(e.code), e.code)
def getDailyTrends(self, date = None, exclude = False):
"""getDailyTrends(date = None, exclude = False)
def getDailyTrends(self, date = None, exclude = False, version = None):
"""getDailyTrends(date = None, exclude = False, version = None)
Returns the top 20 trending topics for each hour in a given day.
Parameters:
date - Optional. Permits specifying a start date for the report. The date should be formatted YYYY-MM-DD.
exclude - Optional. Setting this equal to hashtags will remove all hashtags from the trends list.
version (number) - Optional. API version to request. Entire Twython class defaults to 1, but you can override on a function-by-function or class basis - (version=2), etc.
"""
apiURL = "http://search.twitter.com/trends/daily.json"
version = version or self.apiVersion
apiURL = "http://api.twitter.com/%d/trends/daily.json" % version
questionMarkUsed = False
if date is not None:
apiURL += "?date=%s" % date
@ -1391,8 +1395,10 @@ class setup:
Parameters:
date - Optional. Permits specifying a start date for the report. The date should be formatted YYYY-MM-DD.
exclude - Optional. Setting this equal to hashtags will remove all hashtags from the trends list.
version (number) - Optional. API version to request. Entire Twython class defaults to 1, but you can override on a function-by-function or class basis - (version=2), etc.
"""
apiURL = "http://search.twitter.com/trends/daily.json"
version = version or self.apiVersion
apiURL = "http://api.twitter.com/%d/trends/daily.json" % version
questionMarkUsed = False
if date is not None:
apiURL += "?date=%s" % date