Catch exceptions from HTTP request

We don't need to stop the entire process just because we encountered a
temporary error.
This commit is contained in:
Matt Molyneaux 2018-11-24 23:08:45 +00:00
parent 96fd7ed430
commit 076b41e853
1 changed files with 7 additions and 3 deletions

View File

@ -4,7 +4,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
import mastodon import mastodon
import os, random, re, json import os, random, re, json, traceback
import create import create
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
@ -49,8 +49,12 @@ class ReplyListener(mastodon.StreamListener):
visibility = notification['status']['visibility'] visibility = notification['status']['visibility']
if visibility == "public": if visibility == "public":
visibility = "unlisted" visibility = "unlisted"
client.status_post(toot, post_id, visibility=visibility) try:
print("replied with " + toot) client.status_post(toot, post_id, visibility=visibility)
except Exception:
traceback.print_exc()
else:
print("replied with " + toot)
rl = ReplyListener() rl = ReplyListener()
client.stream_user(rl) client.stream_user(rl)