From 74b42441dcf0893dee83a0c04cc4c5f8bc53f4c0 Mon Sep 17 00:00:00 2001 From: Anna Date: Sat, 10 Apr 2010 10:46:51 -0400 Subject: [PATCH] Changed retweet API to use the patch from http://code.google.com/p/python-twitter/issues/detail?id=130 for consistency. --- README | 2 +- mytwitter.py | 2 +- python-twitter-Retweet.patch | 44 ---------------------------------- python-twitter-retweet-3.patch | 34 ++++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 46 deletions(-) delete mode 100644 python-twitter-Retweet.patch create mode 100644 python-twitter-retweet-3.patch diff --git a/README b/README index 0b6c352..8818202 100644 --- a/README +++ b/README @@ -18,7 +18,7 @@ hg clone https://python-twitter.googlecode.com/hg/ python-twitter cd python-twitter hg update dev patch -p1 < ../mytwitter/python-twitter-GetListStatuses.patch -patch -p1 < ../mytwitter/python-twitter-Retweet.patch +patch -p1 < ../mytwitter/python-twitter-retweet-3.patch python setup.py build python setup.py install --user diff --git a/mytwitter.py b/mytwitter.py index c7aeed2..b0c3b24 100755 --- a/mytwitter.py +++ b/mytwitter.py @@ -128,7 +128,7 @@ class MyTwitter(): def on_retweet(self, widget): - self.api.Retweet(widget.id) + self.api.PostRetweet(widget.id) ### end class MyTwitter diff --git a/python-twitter-Retweet.patch b/python-twitter-Retweet.patch deleted file mode 100644 index 3d21d2c..0000000 --- a/python-twitter-Retweet.patch +++ /dev/null @@ -1,44 +0,0 @@ -diff -r 51ac454d5d89 twitter.py ---- a/twitter.py Thu Dec 31 15:06:42 2009 -0500 -+++ b/twitter.py Fri Apr 09 18:08:08 2010 -0400 -@@ -391,6 +391,10 @@ - >>> list = api.GetList('list_slug') - >>> list.member_count - >>> lists = api.GetUserLists() -+ -+ Retweet API: -+ -+ >>> api.Retweet(id) - ''' - - DEFAULT_CACHE_TIMEOUT = 60 # cache for 1 minute -@@ -690,6 +694,29 @@ - results.append(self.PostUpdate(lines[-1], **kwargs)) - return results - -+ def Retweet(self, id): -+ '''Retweet the specified status update -+ -+ The twitter.Api instance must be authenticated. -+ -+ Args: -+ id: The numerical ID of the status update you want to retweet -+ -+ Returns: -+ A Status instance representing the retweet -+ ''' -+ try: -+ if id: -+ long(id) -+ except: -+ raise TwitterError("id must be a long integer") -+ parameters={'id': id} -+ url = 'http://api.twitter.com/1/statuses/retweet/%s.json' % id -+ json = self._FetchUrl(url, parameters=parameters) -+ data = simplejson.loads(json) -+ self._CheckForTwitterError(data) -+ return NewStatusFromJsonDict(data) -+ - def GetReplies(self, since=None, since_id=None, page=None): - '''Get a sequence of status messages representing the 20 most recent - replies (status updates prefixed with @username) to the authenticating diff --git a/python-twitter-retweet-3.patch b/python-twitter-retweet-3.patch new file mode 100644 index 0000000..91201eb --- /dev/null +++ b/python-twitter-retweet-3.patch @@ -0,0 +1,34 @@ +diff -r 51ac454d5d89 twitter.py +--- a/twitter.py Thu Dec 31 15:06:42 2009 -0500 ++++ b/twitter.py Sat Apr 10 10:42:52 2010 -0400 +@@ -690,6 +690,30 @@ + results.append(self.PostUpdate(lines[-1], **kwargs)) + return results + ++ def PostRetweet(self, id): ++ '''Retweet a tweet with the Retweet API ++ ++ The twitter.Api instance must be authenticated. ++ ++ Args: ++ id: The numerical ID of the tweet you are retweeting ++ ++ Returns: ++ A twitter.Status instance representing the retweet posted ++ ''' ++ if not self._username: ++ raise TwitterError("The twitter.Api instance must be authenticated.") ++ try: ++ if int(id) <= 0: ++ raise TwitterError("'id' must be a positive number") ++ except ValueError: ++ raise TwitterError("'id' must be an integer") ++ url = 'http://api.twitter.com/1/statuses/retweet/%s.json' % id ++ json = self._FetchUrl(url, post_data={}) ++ data = simplejson.loads(json) ++ self._CheckForTwitterError(data) ++ return NewStatusFromJsonDict(data) ++ + def GetReplies(self, since=None, since_id=None, page=None): + '''Get a sequence of status messages representing the 20 most recent + replies (status updates prefixed with @username) to the authenticating