Fix fails

This commit is contained in:
Gabriele De Rosa 2021-01-09 13:08:13 +01:00
parent e47019ab69
commit 8057672929
1 changed files with 18 additions and 2 deletions

16
bot.py
View File

@ -293,12 +293,28 @@ def job():
"active": True, "active": True,
"news": True "news": True
}) })
# Counters
news_sent_counter = 0
news_fail_counter = 0
# Send news to all active user # Send news to all active user
for user in users: for user in users:
try:
# Send photo # Send photo
updater.bot.send_photo(chat_id=user['_id'], photo=open(data['results'], 'rb'), caption="") 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 # Remove tmp files
os.remove(data['plot']) os.remove(data['plot'])