telegram_main.py 952 B

123456789101112131415161718192021222324252627282930313233
  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. strip_file=open(config["saveLocation"]+config["filename"],"rb")
  14. bot.send_photo(chat_id=update.message.chat_id,photo=strip_file)
  15. strip_file.close()
  16. except Exception as err:
  17. print(err)
  18. else:
  19. print("Creation of image failed\n")
  20. print(status)
  21. if __name__ == "__main__":
  22. config = readConfig(platform="telegram")
  23. with open(config["token"]) as token_file:
  24. content = token_file.readlines()
  25. token = content[0].strip()
  26. updater = Updater(token)
  27. dp = updater.dispatcher
  28. dp.add_handler(CommandHandler('strip',newStrip, pass_args=True))
  29. updater.start_polling()
  30. updater.idle()