CHG: Control de errores en feditree

This commit is contained in:
Roboron3042 2024-12-13 22:20:12 +01:00
parent 4ab97cdc49
commit 1d98f9f4f1
1 changed files with 20 additions and 17 deletions

View File

@ -87,13 +87,14 @@ def create_image(accounts):
bot_name = "feditree" bot_name = "feditree"
localedir = './locales' localedir = './locales'
api = get_api('masto.es', "test") api = get_api('masto.es', bot_name)
notifications = get_new_notifications(api, bot_name, ["mention"]) notifications = get_new_notifications(api, bot_name, ["mention"])
previous_ids = list_read(bot_name + "_previous_ids") previous_ids = list_read(bot_name + "_previous_ids")
for notification in notifications: for notification in notifications:
i18n = gettext.translation(bot_name, localedir, fallback=True, languages=[notification.status.language]) i18n = gettext.translation(bot_name, localedir, fallback=True, languages=[notification.status.language])
i18n.install() i18n.install()
try:
if str(notification.account.id) in previous_ids: if str(notification.account.id) in previous_ids:
status = "@" + notification.account.acct + " " status = "@" + notification.account.acct + " "
status += _("I have already generated a feditree for you this year. Try again next year!") status += _("I have already generated a feditree for you this year. Try again next year!")
@ -111,3 +112,5 @@ for notification in notifications:
status += " @/" + account.acct status += " @/" + account.acct
api.status_post(status, media_ids=image, visibility="unlisted", in_reply_to_id=notification.status.id) api.status_post(status, media_ids=image, visibility="unlisted", in_reply_to_id=notification.status.id)
previous_ids.append(notification.account.id) previous_ids.append(notification.account.id)
except:
api.status_post(_("An error ocurred. Please try again or contact my creator"), visibility="direct", in_reply_to_id=notification.status.id)