error handling and deployment
parent
dd45d52186
commit
208a6181a4
|
@ -28,11 +28,19 @@ class MastodonBot(Bot):
|
||||||
except mastodon.MastodonNetworkError:
|
except mastodon.MastodonNetworkError:
|
||||||
logger.error("Mastodon Network Error.")
|
logger.error("Mastodon Network Error.")
|
||||||
return mentions
|
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:
|
except mastodon.MastodonInternalServerError:
|
||||||
try:
|
try:
|
||||||
logger.error("Mastodon Error: 500. Server: " + m.instance()['urls']['streaming_api'])
|
logger.error("Mastodon Error: 500. Server: " + m.instance()['urls']['streaming_api'])
|
||||||
except mastodon.MastodonServerError:
|
except mastodon.MastodonServerError:
|
||||||
logger.error("Mastodon Server Error 500, can't get instance.")
|
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
|
return mentions
|
||||||
except mastodon.MastodonBadGatewayError:
|
except mastodon.MastodonBadGatewayError:
|
||||||
try:
|
try:
|
||||||
|
@ -59,27 +67,30 @@ class MastodonBot(Bot):
|
||||||
logger.error("Unknown Mastodon Server Error.", exc_info=True)
|
logger.error("Unknown Mastodon Server Error.", exc_info=True)
|
||||||
return mentions
|
return mentions
|
||||||
for status in notifications:
|
for status in notifications:
|
||||||
if (status['type'] == 'mention' and
|
try:
|
||||||
|
if (status['type'] == 'mention' and
|
||||||
not user.toot_is_seen(status['status']['uri'])):
|
not user.toot_is_seen(status['status']['uri'])):
|
||||||
# save state
|
# save state
|
||||||
user.toot_witness(status['status']['uri'])
|
user.toot_witness(status['status']['uri'])
|
||||||
# add mention to mentions
|
# add mention to mentions
|
||||||
text = re.sub(r'<[^>]*>', '', status['status']['content'])
|
text = re.sub(r'<[^>]*>', '', status['status']['content'])
|
||||||
text = re.sub(
|
text = re.sub(
|
||||||
"(?<=^|(?<=[^a-zA-Z0-9-_.]))@([A-Za-z]+[A-Za-z0-9-_]+)",
|
"(?<=^|(?<=[^a-zA-Z0-9-_.]))@([A-Za-z]+[A-Za-z0-9-_]+)",
|
||||||
"", text)
|
"", text)
|
||||||
if status['status']['visibility'] == 'public':
|
if status['status']['visibility'] == 'public':
|
||||||
mentions.append(Report(status['account']['acct'],
|
mentions.append(Report(status['account']['acct'],
|
||||||
self,
|
self,
|
||||||
text,
|
text,
|
||||||
status['status']['id'],
|
status['status']['id'],
|
||||||
status['status']['created_at']))
|
status['status']['created_at']))
|
||||||
else:
|
else:
|
||||||
mentions.append(Report(status['account']['acct'],
|
mentions.append(Report(status['account']['acct'],
|
||||||
'mastodonPrivate',
|
'mastodonPrivate',
|
||||||
text,
|
text,
|
||||||
status['status']['id'],
|
status['status']['id'],
|
||||||
status['status']['created_at']))
|
status['status']['created_at']))
|
||||||
|
except TypeError:
|
||||||
|
pass
|
||||||
return mentions
|
return mentions
|
||||||
|
|
||||||
def post(self, user, report):
|
def post(self, user, report):
|
||||||
|
|
|
@ -67,7 +67,7 @@ class TwitterBot(Bot):
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
logger.error("Twitter API Error: Bad Connection", exc_info=True)
|
logger.error("Twitter API Error: Bad Connection", exc_info=True)
|
||||||
except tweepy.TweepError:
|
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 []
|
return []
|
||||||
|
|
||||||
def post(self, user, report):
|
def post(self, user, report):
|
||||||
|
|
|
@ -12,6 +12,8 @@ KillSignal=SIGQUIT
|
||||||
Type=notify
|
Type=notify
|
||||||
StandardError=syslog
|
StandardError=syslog
|
||||||
NotifyAccess=all
|
NotifyAccess=all
|
||||||
|
User=tech
|
||||||
|
Group=www-data
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|
Loading…
Reference in New Issue