From 208a6181a40a227e6362ba6cffefffd4296552d3 Mon Sep 17 00:00:00 2001 From: missytake Date: Mon, 27 Jul 2020 01:14:59 +0200 Subject: [PATCH] error handling and deployment --- active_bots/mastodonbot.py | 51 +++++++++++++++++++------------ active_bots/twitterbot.py | 2 +- deployment/ticketfrei-web.service | 2 ++ 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/active_bots/mastodonbot.py b/active_bots/mastodonbot.py index 8d3d4a6..53d1509 100755 --- a/active_bots/mastodonbot.py +++ b/active_bots/mastodonbot.py @@ -28,11 +28,19 @@ class MastodonBot(Bot): except mastodon.MastodonNetworkError: logger.error("Mastodon Network Error.") return mentions + except mastodon.MastodonAPIError: + try: + logger.error("Mastodon API Error: " + m.instance()['urls']['streaming_api'] + ", city: " + str(user.uid)) + except mastodon.MastodonServerError: + logger.error("Mastodon Server Error 500, can't get instance.") + return mentions except mastodon.MastodonInternalServerError: try: logger.error("Mastodon Error: 500. Server: " + m.instance()['urls']['streaming_api']) except mastodon.MastodonServerError: logger.error("Mastodon Server Error 500, can't get instance.") + except mastodon.MastodonVersionError: + logger.error("Mastodon Server Error 500, server version too low.") return mentions except mastodon.MastodonBadGatewayError: try: @@ -59,27 +67,30 @@ class MastodonBot(Bot): logger.error("Unknown Mastodon Server Error.", exc_info=True) return mentions for status in notifications: - if (status['type'] == 'mention' and + try: + if (status['type'] == 'mention' and not user.toot_is_seen(status['status']['uri'])): - # save state - user.toot_witness(status['status']['uri']) - # add mention to mentions - text = re.sub(r'<[^>]*>', '', status['status']['content']) - text = re.sub( - "(?<=^|(?<=[^a-zA-Z0-9-_.]))@([A-Za-z]+[A-Za-z0-9-_]+)", - "", text) - if status['status']['visibility'] == 'public': - mentions.append(Report(status['account']['acct'], - self, - text, - status['status']['id'], - status['status']['created_at'])) - else: - mentions.append(Report(status['account']['acct'], - 'mastodonPrivate', - text, - status['status']['id'], - status['status']['created_at'])) + # save state + user.toot_witness(status['status']['uri']) + # add mention to mentions + text = re.sub(r'<[^>]*>', '', status['status']['content']) + text = re.sub( + "(?<=^|(?<=[^a-zA-Z0-9-_.]))@([A-Za-z]+[A-Za-z0-9-_]+)", + "", text) + if status['status']['visibility'] == 'public': + mentions.append(Report(status['account']['acct'], + self, + text, + status['status']['id'], + status['status']['created_at'])) + else: + mentions.append(Report(status['account']['acct'], + 'mastodonPrivate', + text, + status['status']['id'], + status['status']['created_at'])) + except TypeError: + pass return mentions def post(self, user, report): diff --git a/active_bots/twitterbot.py b/active_bots/twitterbot.py index 87e14f9..4c53115 100755 --- a/active_bots/twitterbot.py +++ b/active_bots/twitterbot.py @@ -67,7 +67,7 @@ class TwitterBot(Bot): except requests.exceptions.ConnectionError: logger.error("Twitter API Error: Bad Connection", exc_info=True) except tweepy.TweepError: - logger.error("Twitter API Error: General Error", exc_info=True) + logger.error("Twitter API Error: General Error. User: " + str(user.uid), exc_info=True) return [] def post(self, user, report): diff --git a/deployment/ticketfrei-web.service b/deployment/ticketfrei-web.service index b98d76f..a8ca380 100644 --- a/deployment/ticketfrei-web.service +++ b/deployment/ticketfrei-web.service @@ -12,6 +12,8 @@ KillSignal=SIGQUIT Type=notify StandardError=syslog NotifyAccess=all +User=tech +Group=www-data [Install] WantedBy=multi-user.target