telegram_main.py 905 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/python3
  2. from telegram.ext import Updater, CommandHandler
  3. from randstrip import createStrip,readConfig
  4. import requests
  5. import os
  6. fileDir = os.path.dirname(os.path.abspath(__file__))
  7. fileDir = fileDir +"/"
  8. def newStrip(bot, update, args):
  9. config = readConfig(platform="telegram",profile=args)
  10. status = createStrip(config)
  11. if status == 0:
  12. try:
  13. bot.send_photo(chat_id=update.message.chat_id,photo=open(config["saveLocation"]+config["filename"],"rb"))
  14. except Exception as err:
  15. print(err)
  16. else:
  17. print("Creation of image failed\n")
  18. print(status)
  19. if __name__ == "__main__":
  20. config = readConfig(platform="telegram")
  21. with open(config["token"]) as token_file:
  22. content = token_file.readlines()
  23. token = content[0].strip()
  24. updater = Updater(token)
  25. dp = updater.dispatcher
  26. dp.add_handler(CommandHandler('strip',newStrip, pass_args=True))
  27. updater.start_polling()
  28. updater.idle()