From dc4f9240ca6a22d0e28b8373d02f911cb27a3cfc Mon Sep 17 00:00:00 2001 From: Josh Roesslein Date: Sun, 20 Sep 2009 19:29:25 -0500 Subject: [PATCH] Added statuses/retweets method. Implemented retweets parser. Added retweet model. --- CHANGES | 6 ++++-- ROADMAP | 2 +- tweepy/api.py | 9 +++++++++ tweepy/models.py | 7 ++++++- tweepy/parsers.py | 17 +++++++++++++++++ 5 files changed, 37 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index 8136b7b..d2a273a 100644 --- a/CHANGES +++ b/CHANGES @@ -5,8 +5,10 @@ during upgrade will be listed here. ======================= + Fixes + Google App Engine fixes (thanks Thomas Bohmbach, Jr) -+ Added Retweet API methods -+ Added Retweet Streaming method ++ API + + Added Retweet API methods + + Added Retweet Streaming method + + New model: Retweet + OAuthHandler + Added set_request_token() method + Added support for "sign in with twitter". diff --git a/ROADMAP b/ROADMAP index 6d52d14..c643561 100644 --- a/ROADMAP +++ b/ROADMAP @@ -4,6 +4,6 @@ The plan of attack for the next version of Tweepy. ============ + implement win32 file locking for FileCache + add retweet API methods [DONE] - + add statuses/retweets method + + add statuses/retweets method [DONE] + add retweet streaming method [DONE] diff --git a/tweepy/api.py b/tweepy/api.py index ecb9a25..ee85694 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -133,6 +133,15 @@ class API(object): require_auth = True ) + """Get the retweets of the specified tweet ID""" + def retweets(self, id, *args, **kargs): + return bind_api( + path = '/statuses/retweets/%s.json' % id, + parser = parse_retweets, + allowed_param = ['count'], + require_auth = True + )(self, *args, **kargs) + """Show user""" get_user = bind_api( path = '/users/show.json', diff --git a/tweepy/models.py b/tweepy/models.py index 6e75a42..9d50cd3 100644 --- a/tweepy/models.py +++ b/tweepy/models.py @@ -109,6 +109,10 @@ class SearchResult(Model): pass +class Retweet(Model): + + pass + # link up default model implementations. models = { 'status': Status, @@ -116,6 +120,7 @@ models = { 'direct_message': DirectMessage, 'friendship': Friendship, 'saved_search': SavedSearch, - 'search_result': SearchResult + 'search_result': SearchResult, + 'retweet': Retweet, } diff --git a/tweepy/parsers.py b/tweepy/parsers.py index 00a7bf6..9d15a65 100644 --- a/tweepy/parsers.py +++ b/tweepy/parsers.py @@ -212,3 +212,20 @@ def parse_search_results(data, api): result_objects.append(_parse_search_result(obj, api)) return result_objects +def _parse_retweet(obj, api): + + retweet = models['retweet']() + for k,v in obj.items(): + if k == 'retweeting_user': + setattr(retweet, k, _parse_user(v, api)) + else: + setattr(retweet, k, v) + return retweet + +def parse_retweets(data, api): + + retweets = [] + for obj in json.loads(data): + retweets.append(_parse_retweet(obj, api)) + return retweets + -- 2.25.1