From f65b743b32661a53b3544f8e56758194b725f5e7 Mon Sep 17 00:00:00 2001 From: Anna Date: Sun, 11 Apr 2010 01:10:45 -0400 Subject: [PATCH] Replaced complicated GetReplies stuff with a simple implementation of GetMentions --- mytwitter.py | 8 +---- python-twitter-GetMentions.patch | 53 ++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 python-twitter-GetMentions.patch diff --git a/mytwitter.py b/mytwitter.py index cb87eac..4400523 100755 --- a/mytwitter.py +++ b/mytwitter.py @@ -76,13 +76,7 @@ class MyTwitter(): if self.list is None or self.list == 'Home': statuses = self.api.GetHomeTimeline(count=self.num_entries) elif self.list == '@' + self.username: - statuses = [] - page = 1 - num_needed = self.num_entries - while num_needed > 0: - statuses.extend(self.api.GetReplies(page=page)) - num_needed -= 20 - page += 1 + statuses = self.api.GetMentions(count=self.num_entries) else: statuses = self.api.GetListStatuses(self.list, per_page=self.num_entries) diff --git a/python-twitter-GetMentions.patch b/python-twitter-GetMentions.patch new file mode 100644 index 0000000..6434e48 --- /dev/null +++ b/python-twitter-GetMentions.patch @@ -0,0 +1,53 @@ +diff -r 51ac454d5d89 twitter.py +--- a/twitter.py Thu Dec 31 15:06:42 2009 -0500 ++++ b/twitter.py Sun Apr 11 01:08:53 2010 -0400 +@@ -722,6 +722,49 @@ + self._CheckForTwitterError(data) + return [NewStatusFromJsonDict(x) for x in data] + ++ def GetMentions(self, since_id=None, max_id=None, count=None, page=None): ++ '''Get a sequence of status messages representing status updates containing ++ @username for the authenticated user ++ ++ Args: ++ since_id: ++ Returns only public statuses with an ID greater than (that is, ++ more recent than) the specified ID. [Optional] ++ max_id: ++ Returns only statuses with an ID less than (that is, older ++ than) or equal to the specified ID. [optional] ++ count: ++ Specifies the number of statuses to retrieve. May not be ++ greater than 200. [optional] ++ page: ++ Specifies the page of results to retrieve. Note: there are ++ pagination limits. [optional] ++ ++ Returns: ++ A sequence of Status instances, one for each mention of the user. ++ ''' ++ url = 'http://api.twitter.com/1/statuses/mentions.json' ++ if not self._username: ++ raise TwitterError("The twitter.Api instance must be authenticated.") ++ parameters = {} ++ if since_id: ++ parameters['since_id'] = since_id ++ if max_id: ++ parameters['max_id'] = max_id ++ if count: ++ try: ++ if int(count) > 200: ++ raise TwitterError("'count' may not be greater than 200") ++ except ValueError: ++ raise TwitterError("'count' must be an integer") ++ parameters['count'] = count ++ if page: ++ parameters['page'] = page ++ json = self._FetchUrl(url, parameters=parameters) ++ data = simplejson.loads(json) ++ self._CheckForTwitterError(data) ++ return [NewStatusFromJsonDict(x) for x in data] ++ + def GetFavorites(self, + user=None, + page=None):