Add support for quoted_status in html_for_tweet()

This commit is contained in:
ping 2015-08-17 14:22:32 +08:00
parent 26ea0f3ae0
commit 62d51c7431

View file

@ -528,7 +528,7 @@ class Twython(EndpointsMixin, object):
return str(text) return str(text)
@staticmethod @staticmethod
def html_for_tweet(tweet, use_display_url=True, use_expanded_url=False): def html_for_tweet(tweet, use_display_url=True, use_expanded_url=False, expand_quoted_status=False):
"""Return HTML for a tweet (urls, mentions, hashtags replaced with links) """Return HTML for a tweet (urls, mentions, hashtags replaced with links)
:param tweet: Tweet object from received from Twitter API :param tweet: Tweet object from received from Twitter API
@ -595,4 +595,16 @@ class Twython(EndpointsMixin, object):
text = text.replace(tweet['text'][start:end], text = text.replace(tweet['text'][start:end],
url_html % (entity['url'], shown_url)) url_html % (entity['url'], shown_url))
if expand_quoted_status and tweet['is_quote_status']:
quoted_status = tweet['quoted_status']
text += '<blockquote class="twython-quote">%(quote)s<cite><a href="%(quote_tweet_link)s">' \
'<span class="twython-quote-user-name">%(quote_user_name)s</span>' \
'<span class="twython-quote-user-screenname">@%(quote_user_screen_name)s</span></a>' \
'</cite></blockquote>' % \
{'quote': Twython.html_for_tweet(quoted_status, use_display_url, use_expanded_url, False),
'quote_tweet_link': 'https://twitter.com/%s/status/%s' %
(quoted_status['user']['screen_name'], quoted_status['id_str']),
'quote_user_name': quoted_status['user']['name'],
'quote_user_screen_name': quoted_status['user']['screen_name']}
return text return text