from progressreporting.TelegramProgressReporter import TelegramProgressReporter
MAX_K = 99999
with TelegramProgressReporter(
total = MAX_K,
telegram_token = 'token of your bot',
telegram_chat_id = 'ID of the chat to send the messages',
loop_name = 'Optional loop name'):
as reporter:
for k in range(MAX_K):
# Do some stuff...
reporter.update(1) # 1 means 1/MAX_K completed.
The reporter will:
Send a message to the chat when it enters the with context.
Estimate when will it finished.
Update the original message in the chat as the loop goes on.
Send a new message when it goes out of the with context stating if there was an error or not.
The reporter will not:
Raise any error. Your program will never crash due to the reporter.
Hang or make your program slower.
Spam your Telegram chat with hundreds of messages, just 2 messages per loop: At the start and at the end.
Print anything in your terminal. Your terminal stays clean!
You will:
Get released of having to check whether things are still going on. 🏖️🏝️
Know when the program ends.
Run first example and come back!
Run the rest of the examples.
Conclusions
Presented a simple pure Python package that reports the progress of a loop to a Telegram chat using a bot.
Real time updates to your Telegram account: Mobile app, desktop app or web app.
Effortless: Just 3 extra lines of code.
Safe: Does not rises any errors.
Releases you to check whether the program is still running; more time to worry about important stuff!