From a18897fcde342661f7e2e45796e3ef9ae5dfe926 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Thu, 16 Dec 2010 13:04:58 -0600 Subject: [PATCH] print the native tweet of retweets (rather than the possibly-truncated one) this now depends on a modified twitter.py, although i could probably send my patch upstream --- modules/Twitter.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/modules/Twitter.py b/modules/Twitter.py index aa16ca5..3966e5a 100644 --- a/modules/Twitter.py +++ b/modules/Twitter.py @@ -84,20 +84,30 @@ class Twitter(Module): if whats[1] == 'status' and len(whats) == 3: try: tweet = self.twit.GetStatus(whats[2]) - return self.reply(connection, replypath, tweet.user.name.encode('utf-8', 'ignore') + ': ' + tweet.text.encode('utf-8', 'ignore')) + return self.reply(connection, replypath, self.tweet_or_retweet_text(tweet)) except twitter.TwitterError as e: return self.reply(connection, replypath, 'Couldn\'t obtain status: ' + str(e)) elif whats[1] == 'user' and len(whats) == 3: try: - # TODO: on the fence about this. including native retweets could be confusing - # (the displayed user would be someone other than who was searched for), but - # if the user's last 30 tweets are RTs, this will be empty, which also sucks - tweets = self.twit.GetUserTimeline(screen_name=whats[2], count=30, include_rts=False) + tweets = self.twit.GetUserTimeline(screen_name=whats[2], count=30, include_rts=True) if tweets: tweet = tweets[0] - return self.reply(connection, replypath, tweet.user.name.encode('utf-8', 'ignore') + ': ' + tweet.text.encode('utf-8', 'ignore')) + return self.reply(connection, replypath, self.tweet_or_retweet_text(tweet)) except twitter.TwitterError as e: return self.reply(connection, replypath, 'Couldn\'t obtain status: ' + str(e)) + def tweet_or_retweet_text(self, tweet): + """ + Return a string of the author and text body of a status, + accounting for whether or not the fetched status is a + retweet. + """ + + if tweet.retweeted_status: + retweet = tweet.retweeted_status + return '(RT) %s: %s' % (retweet.user.name.encode('utf-8', 'ignore'), retweet.text.encode('utf-8', 'ignore')) + else: + return '%s: %s' % (tweet.user.name.encode('utf-8', 'ignore'), tweet.text.encode('utf-8', 'ignore')) + # vi:tabstop=4:expandtab:autoindent # kate: indent-mode python;indent-width 4;replace-tabs on;