Skip to main content

telegram-coffee-break

It's time to take a coffee break! your python code is running, and you'll be notified through telegram when you will have your results.

Goal

Create a telegram bot that will send you notifications on your phone to follow your code progress.

Installation

pip install telegram-coffee-break

Preparation

First: You will need to create a new telegram bot as follow:

https://docs.microsoft.com/en-us/azure/bot-service/bot-service-channel-connect-telegram?view=azure-bot-service-4.0

Go to the BotFather (if you open it in desktop, make sure you have the Telegram app), then create new bot by sending the /newbot command. Follow the steps until you get the username and token for your bot. You can go to your bot by accessing this URL: https://telegram.me/YOUR_BOT_USERNAME and your token should looks like this.

7044NNNNN:AAEtcZ*************

Keep the token safe in a file and set your bot.

Next: You need to find your telegram ID

https://support.bigonechina.com/hc/en-us/articles/360008014894-How-to-get-the-Telegram-user-ID-

Go to the userinfobot and send /start. He will give you your personal ID.

Id: 871NNNNN
First: lol
Last: lolilol
Lang: en

Usage example

Simple example where you simply receive a notification at a certain point in the progress of the code.

from telegrambotalarm import TelegramBot

TOKEN = 'NNNNNNNNNN:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
MYID = 'NNNNNNNNN'

bot = TelegramBot(TOKEN, MYID)
bot.send_message('Your code is running')

... do modeling etc ...

message = {
    train accuracy : train_acc,
    test accuracy : test_acc
}
bot.send_message(message)
bot.send_image('decision_tree.png', caption=message)

Best example where you are informed if an error occurs during the execution of a piece of code.

def train_model():
    ## do something ##
    results = {
        'train accuracy' : train_acc,
        'test accuracy' : test_acc
    }
    return results

from telegrambotalarm import TelegramBot
import traceback

TOKEN = 'nnnnnnnnnn:xxxxxxxxxxxxxxxxxxxxx'
MYID = 'nnnnnnnn'

bot = TelegramBot(TOKEN, MYID)

# Run this
try:
    results = train_model()

# If error occurs, send the error with its trace
except Exception as e:
    print(traceback.format_exc())
    bot.send_error_message(traceback.format_exc())

bot.send_message(results)
bot.send_image('decision_tree.png', caption=message)

Metadata

Release files for telegram-coffee-break 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for telegram-coffee-break 0.2.1
File Size Uploaded
telegram-coffee-break-0.2.1.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for telegram-coffee-break 0.2.1
File Interpreter ABI Platform
telegram_coffee_break-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 10.1 kB

Release files / telegram-coffee-break-0.2.1.tar.gz

Download URL telegram-coffee-break-0.2.1.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8575f710e33216367add3e7c4f6d7c75fc5a836a115403073df764fdb989b303
BLAKE2b-256 checksum
How to use checksums
ace7b222ae3b2ce7626ac2a9f8567f35bba8decbc75b573a0f3b98a93b2d633b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.7.7

Release files / telegram_coffee_break-0.2.1-py3-none-any.whl

Download URL telegram_coffee_break-0.2.1-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c2673ce03ee8f044c77b3bc3f0886f4af6d7f8adb183c010a55308ca9b006e03
BLAKE2b-256 checksum
How to use checksums
4f875445ee9a142654c6e84e63ea5881f90c47b0baba980fc9ec9de0bf3dba71
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.7.7

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page