optionally print the source of the tweet in question

useful if you don't know it, such as if the tweet was specified
by id rather than by user
This commit is contained in:
Brian S. Stephan 2010-12-16 15:22:34 -06:00
parent a18897fcde
commit 57ddba744e
1 changed files with 11 additions and 5 deletions

View File

@ -84,7 +84,7 @@ class Twitter(Module):
if whats[1] == 'status' and len(whats) == 3:
try:
tweet = self.twit.GetStatus(whats[2])
return self.reply(connection, replypath, self.tweet_or_retweet_text(tweet))
return self.reply(connection, replypath, self.tweet_or_retweet_text(tweet=tweet, print_source=True))
except twitter.TwitterError as e:
return self.reply(connection, replypath, 'Couldn\'t obtain status: ' + str(e))
elif whats[1] == 'user' and len(whats) == 3:
@ -92,11 +92,11 @@ class Twitter(Module):
tweets = self.twit.GetUserTimeline(screen_name=whats[2], count=30, include_rts=True)
if tweets:
tweet = tweets[0]
return self.reply(connection, replypath, self.tweet_or_retweet_text(tweet))
return self.reply(connection, replypath, self.tweet_or_retweet_text(tweet=tweet))
except twitter.TwitterError as e:
return self.reply(connection, replypath, 'Couldn\'t obtain status: ' + str(e))
def tweet_or_retweet_text(self, tweet):
def tweet_or_retweet_text(self, tweet, print_source=False):
"""
Return a string of the author and text body of a status,
accounting for whether or not the fetched status is a
@ -105,9 +105,15 @@ class Twitter(Module):
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'))
if print_source:
return '%s (RT %s): %s' % (tweet.user.name.encode('utf-8', 'ignore'), retweet.user.name.encode('utf-8', 'ignore'), retweet.text.encode('utf-8', 'ignore'))
else:
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'))
if print_source:
return '%s: %s' % (tweet.user.name.encode('utf-8', 'ignore'), tweet.text.encode('utf-8', 'ignore'))
else:
return '%s' % (tweet.text.encode('utf-8', 'ignore'))
# vi:tabstop=4:expandtab:autoindent
# kate: indent-mode python;indent-width 4;replace-tabs on;