From 8057672929c973be92cc451b53bf3bb9c6ac9857 Mon Sep 17 00:00:00 2001 From: Gabriele De Rosa Date: Sat, 9 Jan 2021 13:08:13 +0100 Subject: [PATCH] Fix fails --- bot.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/bot.py b/bot.py index 9d2cb03..7666558 100644 --- a/bot.py +++ b/bot.py @@ -293,12 +293,28 @@ def job(): "active": True, "news": True }) + + # Counters + news_sent_counter = 0 + news_fail_counter = 0 # Send news to all active user for user in users: - # Send photo - updater.bot.send_photo(chat_id=user['_id'], photo=open(data['results'], 'rb'), caption="") + try: + # Send photo + updater.bot.send_photo(chat_id=user['_id'], photo=open(data['results'], 'rb'), caption="") + # Count news successfully sent + news_sent_counter = news_sent_counter + 1 + # Log + print('[JOB] Message successfully sent to ', user['_id']) + except: + # Count news fail + news_fail_counter = news_fail_counter + 1 + # Error on sending + print('[JOB] Failed to send to ', user['_id']) + # Log results + print("[JOB] Results: {sent} message sent, {fail} messages failed.".format(sent=news_sent_counter, fail=news_fail_counter)) # Remove tmp files os.remove(data['plot'])