├── .gitignore ├── ipytelegram.py └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | -------------------------------------------------------------------------------- /ipytelegram.py: -------------------------------------------------------------------------------- 1 | import telepot 2 | from IPython.core.magic import Magics, magics_class, line_magic, cell_magic 3 | 4 | 5 | @magics_class 6 | class TelegramMagics(Magics): 7 | 8 | def __init__(self, shell): 9 | super(TelegramMagics, self).__init__(shell) 10 | self.token = None 11 | self.user_id = None 12 | self.bot = None 13 | 14 | @line_magic 15 | def telegram_setup(self, line): 16 | r = line.strip().split() 17 | if len(r) == 2: 18 | self.token, self.user_id = r 19 | self.bot = telepot.Bot(self.token) 20 | else: 21 | raise ValueError 22 | 23 | @cell_magic 24 | def telegram_send(self, line, cell): 25 | self.shell.run_cell(cell) 26 | self.bot.sendMessage(self.user_id, line) 27 | 28 | 29 | def load_ipython_extension(ipython): 30 | magics = TelegramMagics(ipython) 31 | ipython.register_magics(magics) 32 | 33 | 34 | def unload_ipython_extension(ipython): 35 | pass 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ipytelegram 2 | IPython magic for Telegram notifications, 3 | 4 | or get a push once a model is finally trained. 5 | 6 | Requires 7 | ------------- 8 | pip install telepot 9 | 10 | Install 11 | ------------- 12 | %install_ext https://raw.githubusercontent.com/kalaidin/ipytelegram/master/ipytelegram.py 13 | 14 | Load 15 | ------------- 16 | %load_ext ipytelegram 17 | 18 | Initialize 19 | ------------- 20 | %telegram_setup 21 | 22 | Use 23 | ------------- 24 | Cell magic as follows: 25 | 26 | %%telegram_send I am finally trained! 27 | model.train(epochs=1e10) 28 | 29 | will send "I am finally trained!" to you on behalf of your bot once the cell is completed. 30 | 31 | Token 32 | ------------- 33 | Talk to [BotFather](https://telegram.me/botfather) to create a bot and get a token. 34 | 35 | ID 36 | ------------- 37 | The bot is not able to start a conversation with you, so talk to him first, then run: 38 | 39 | import telepot 40 | bot = telepot.Bot() 41 | response = bot.getUpdates() 42 | 43 | Look up `response` for your ID. --------------------------------------------------------------------------------