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:
parent
e2989b639c
commit
a18897fcde
@ -84,20 +84,30 @@ class Twitter(Module):
|
|||||||
if whats[1] == 'status' and len(whats) == 3:
|
if whats[1] == 'status' and len(whats) == 3:
|
||||||
try:
|
try:
|
||||||
tweet = self.twit.GetStatus(whats[2])
|
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:
|
except twitter.TwitterError as e:
|
||||||
return self.reply(connection, replypath, 'Couldn\'t obtain status: ' + str(e))
|
return self.reply(connection, replypath, 'Couldn\'t obtain status: ' + str(e))
|
||||||
elif whats[1] == 'user' and len(whats) == 3:
|
elif whats[1] == 'user' and len(whats) == 3:
|
||||||
try:
|
try:
|
||||||
# TODO: on the fence about this. including native retweets could be confusing
|
tweets = self.twit.GetUserTimeline(screen_name=whats[2], count=30, include_rts=True)
|
||||||
# (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)
|
|
||||||
if tweets:
|
if tweets:
|
||||||
tweet = tweets[0]
|
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:
|
except twitter.TwitterError as e:
|
||||||
return self.reply(connection, replypath, 'Couldn\'t obtain status: ' + str(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
|
# vi:tabstop=4:expandtab:autoindent
|
||||||
# kate: indent-mode python;indent-width 4;replace-tabs on;
|
# kate: indent-mode python;indent-width 4;replace-tabs on;
|
||||||
|
Loading…
Reference in New Issue
Block a user