Advertisement
Guest User

AlarmClock

a guest
Aug 23rd, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. import telebot
  2. from datetime import *
  3. from threading import Thread
  4.  
  5. bot = telebot.TeleBot("819452497:AAEyEtgrW50WLM9sR1Kp37VeICQGNBFQRhY")
  6.  
  7. alc = {}
  8.  
  9. @bot.message_handler(content_types=["text"])
  10. def check(mes):
  11. id = mes.chat.id
  12. text = mes.text
  13. if text == "/start":
  14. bot.send_message(id, "Welcome.\nTo set a new alarm clock, text a command in a following manner:\nset HH:MM:SS\nTo erase the alarm clock, text \"clear\".")
  15. alc[id] = 999999
  16. else:
  17. spl = text.split(' ')
  18. if spl[0] == "set":
  19. h = int(spl[1].split(':')[0])
  20. m = int(spl[1].split(':')[1])
  21. s = int(spl[1].split(':')[2])
  22. alc[id] = h*3600 + m*60 + s
  23. bot.send_message(id, "Alarm clock set.")
  24. elif text == "clear":
  25. alc[id] = 999999
  26. bot.send_message(id, "Alarm clock deleted.")
  27.  
  28.  
  29. def checkTime():
  30. while True:
  31. hms = datetime.now().strftime("%H %M %S").split(' ')
  32. currtime = int(hms[0]) * 3600 + int(hms[1]) * 60 + int(hms[2])
  33. for k in alc.keys():
  34. if currtime >= alc[k]:
  35. alc[k] += 10
  36. bot.send_message(k, "ALARM!!! ALARM!!! (text \"clear\" to stop the alarm)")
  37.  
  38.  
  39. timeThread = Thread(target = checkTime)
  40. timeThread.start()
  41.  
  42. bot.polling(none_stop=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement