Skip to content

Instantly share code, notes, and snippets.

@timoteoramos
Created September 25, 2018 20:49
Show Gist options
  • Save timoteoramos/260b6e8cdd1496555d5e0750ae38e954 to your computer and use it in GitHub Desktop.
Save timoteoramos/260b6e8cdd1496555d5e0750ae38e954 to your computer and use it in GitHub Desktop.
telegram-stdout.py
#!/usr/bin/python3
# Remember to install the pyBotTelegramAPI package (usually from pip)
# It should works with Python 3.4 and above
import telebot, socket, subprocess, sys
BOT_TOKEN='<YOUR BOT TOKEN>'
DESTINATION='<DESTINATION ID>'
cmd = subprocess.Popen(sys.argv[1:], stdout=subprocess.PIPE)
out, err = cmd.communicate()
tb = telebot.TeleBot(BOT_TOKEN)
tb.send_message(DESTINATION, '<b>%s#</b> %s\n\n<pre>%s</pre>' % (socket.gethostname(), ' '.join(sys.argv[1:]), out.decode('utf-8')), parse_mode='HTML')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment