-
-
Save evdokimovm/f41c68c1174c97fcb98322e4a5a6d1da to your computer and use it in GitHub Desktop.
I'm bored. Python telegram bot for posting desktop screenshots.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# FIXME: requirements.txt | |
# pip3 install python-telegram-bot --upgrade | |
# pip3 install pyscreenshot | |
# pip3 install pillow | |
from telegram.ext import Updater | |
from telegram.ext import CommandHandler | |
import pyscreenshot as ImageGrab | |
import os | |
import time | |
token = os.getenv('TOKEN') | |
if not token: | |
print("You need to export TOKEN=YOURTELEGRAMTOKEN") | |
exit() | |
updater = Updater(token=token) | |
dispatcher = updater.dispatcher | |
def start(bot, update): | |
bot.send_message(chat_id=update.message.chat_id, text="Send a /capture request to show your bot's desktop") | |
def capture(bot, update): | |
bot.send_message(chat_id=update.message.chat_id, text="Capturing in 2 seconds") | |
print("\aHeads up! new screenshot in 2 seconds") | |
time.sleep(2) | |
im = ImageGrab.grab() | |
im.save("screen2.png", "PNG") | |
print("Sending...") | |
bot.send_photo(chat_id=update.message.chat_id, photo=open('screen2.png', 'rb')) | |
print("Sent") | |
start_handler = CommandHandler('start', start) | |
dispatcher.add_handler(start_handler) | |
capture_handler = CommandHandler('capture', capture) | |
dispatcher.add_handler(capture_handler) | |
print("Running bot now.") | |
updater.start_polling() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment