twitter: catch update exceptions

We don't need to kill the whole bot if tweets fail, just log it.

Change-Id: Id874fd6b46f0ef48b1f6fef707672fa467e1c268
This commit is contained in:
Ian Wienand 2022-04-06 11:04:53 +10:00
parent a2bf4189e7
commit 0b290dc863
1 changed files with 12 additions and 8 deletions

View File

@ -239,6 +239,7 @@ class UpdateInterface(object):
class Tweet(UpdateInterface):
log = logging.getLogger("statusbot.tweet")
def __init__(self, config):
self.consumer_key = config.get('twitter', 'consumer_key')
@ -262,14 +263,17 @@ class Tweet(UpdateInterface):
tweet = tweets[i]
tweets[i] = tweet + " %d/%d" % (i+1, len(tweets))
last_tweet = None
for tweet in tweets:
if not last_tweet:
last_tweet = self.api.update_status(status=tweet)
else:
last_tweet = self.api.update_status(status=tweet,
in_reply_to_status_id = last_tweet.id,
auto_populate_reply_metadata=True)
try:
last_tweet = None
for tweet in tweets:
if not last_tweet:
last_tweet = self.api.update_status(status=tweet)
else:
last_tweet = self.api.update_status(status=tweet,
in_reply_to_status_id = last_tweet.id,
auto_populate_reply_metadata=True)
except tweepy.TweepyException as e:
self.log.exception("Failed to tweet")
def alert(self, msg=None):
self.update(msg)