Skip to content

Instantly share code, notes, and snippets.

@angch
Last active March 19, 2023 15:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save angch/c726fef4d819c81b5744c751164e4eac to your computer and use it in GitHub Desktop.
Save angch/c726fef4d819c81b5744c751164e4eac to your computer and use it in GitHub Desktop.
I'm bored. Python telegram bot for posting desktop screenshots.
#!/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()
@pismiskedi
Copy link

thank you <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment