wyh_bot.py 825 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env python3
  2. import logging
  3. import telegram.ext
  4. from telegram.ext import Updater
  5. from time import localtime, sleep
  6. def callback(context: telegram.ext.CallbackContext):
  7. if 0 <= localtime().tm_hour < 8:
  8. context.job.enabled = False
  9. return
  10. context.bot.send_message(chat_id='<CHAT_ID>',
  11. text='Did you wash your hands recently?')
  12. logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(7message)s',
  13. level=logging.INFO)
  14. updater = Updater(token='<BOT_TOKEN>', use_context=True)
  15. job_queue = updater.job_queue
  16. job_hour = job_queue.run_repeating(callback, interval=3600, first=0)
  17. updater.start_polling()
  18. while True:
  19. if localtime().tm_hour >= 8 and job_hour.enabled == False:
  20. job_hour.enabled = True
  21. sleep(300)