tootbot: Reconnect on network connection loss

pull/315/merge
Mike Lang 1 year ago committed by Mike Lang
parent e551baaf17
commit 0fde659d15

@ -2,6 +2,7 @@
import logging import logging
import argh import argh
import time
import yaml import yaml
import mastodon import mastodon
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
@ -225,8 +226,15 @@ def main(conf_file, stream="bot-spam", post_topic="Toots from Desert Bus", notif
mastodon_client = mastodon.Mastodon(api_base_url=mc["url"], access_token=mc["access_token"]) mastodon_client = mastodon.Mastodon(api_base_url=mc["url"], access_token=mc["access_token"])
listener = Listener(zulip_client, stream, post_topic, notification_topic) listener = Listener(zulip_client, stream, post_topic, notification_topic)
logging.info("Starting") RETRY_INTERVAL = 1
mastodon_client.stream_user(listener)
while True:
logging.info("Starting")
try:
mastodon_client.stream_user(listener)
except mastodon.MastodonNetworkError:
logging.warning(f"Lost connection, reconnecting in {RETRY_INTERVAL}s")
time.sleep(RETRY_INTERVAL)
@cli @cli

Loading…
Cancel
Save