Giter Club home page Giter Club logo

telegram-coffee-break's Introduction

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

Every details are explained in this post on

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

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

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)

telegram-coffee-break's People

Contributors

dicap1 avatar romaingratier avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.