From 6e463fbc23f627024cbd09c0979d1b77b85d2712 Mon Sep 17 00:00:00 2001 From: dgw Date: Sun, 16 Feb 2020 02:46:51 -0600 Subject: [PATCH] twitter: fix some quoted tweets causing errors Someone please eliminate this false `full_text`/`text` dichotomy from the Twitter API. --- sopel_modules/twitter/twitter.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sopel_modules/twitter/twitter.py b/sopel_modules/twitter/twitter.py index 632bead..ae204ea 100644 --- a/sopel_modules/twitter/twitter.py +++ b/sopel_modules/twitter/twitter.py @@ -72,9 +72,14 @@ def get_url(bot, trigger, match): '| {content[favorite_count]} ♥s').format(content=content, text=text) all_urls = content['entities']['urls'] if content['is_quote_status']: + try: + text = content['quoted_status']['full_text'] + except KeyError: + text = content['quoted_status']['text'] + text.replace("\n", " \u23CE ") # Unicode symbol to indicate line-break message += ('| Quoting {content[quoted_status][user][name]} ' '(@{content[quoted_status][user][screen_name]}): ' - '{content[quoted_status][text]}').format(content=content) + '{text}').format(content=content, text=text) quote_id = content['quoted_status']['id_str'] for url in content['entities']['urls']: expanded_url = url['expanded_url']