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
This commit is contained in:
Brian S. Stephan 2010-12-16 13:04:58 -06:00
parent e2989b639c
commit a18897fcde
1 changed files with 16 additions and 6 deletions

View File

@ -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;