fix twitter account setting and catch exceptions

This commit is contained in:
Ville Ranki 2020-01-10 22:19:49 +02:00
parent a37938fbff
commit 0723dea55e
1 changed files with 9 additions and 4 deletions

View File

@ -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 <a href="https://twitter.com{tweet.tweet_url}">{account}</a>: {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 <a href="https://twitter.com{tweet.tweet_url}">{account}</a>: {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)