From 0723dea55e3c8a8f55d358dc275fe92c35bf5679 Mon Sep 17 00:00:00 2001 From: Ville Ranki Date: Fri, 10 Jan 2020 22:19:49 +0200 Subject: [PATCH] fix twitter account setting and catch exceptions --- modules/twitter.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/twitter.py b/modules/twitter.py index a21c4f7..41f71ca 100644 --- a/modules/twitter.py +++ b/modules/twitter.py @@ -7,7 +7,12 @@ class MatrixModule(PollingService): service_name = 'Twitter' async def poll_implementation(self, bot, account, roomid, send_messages): - for tweet in query_tweets_from_user("twitter", limit=1): - if tweet.tweet_id not in self.known_ids: - await bot.send_html(bot.get_room_by_id(roomid), f'Twitter {account}: {tweet.text}', f'Twitter {account}: {tweet.text} - https://twitter.com{tweet.tweet_url}') - self.known_ids.add(tweet.tweet_id) + try: + for tweet in query_tweets_from_user(account, limit=1): + if tweet.tweet_id not in self.known_ids: + if send_messages: + await bot.send_html(bot.get_room_by_id(roomid), f'Twitter {account}: {tweet.text}', f'Twitter {account}: {tweet.text} - https://twitter.com{tweet.tweet_url}') + self.known_ids.add(tweet.tweet_id) + except Exception: + print('Polling twitter account failed:') + traceback.print_exc(file=sys.stderr)