Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import telebot
- from datetime import *
- from threading import Thread
- bot = telebot.TeleBot("819452497:AAEyEtgrW50WLM9sR1Kp37VeICQGNBFQRhY")
- alc = {}
- @bot.message_handler(content_types=["text"])
- def check(mes):
- id = mes.chat.id
- text = mes.text
- if text == "/start":
- 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\".")
- alc[id] = 999999
- else:
- spl = text.split(' ')
- if spl[0] == "set":
- h = int(spl[1].split(':')[0])
- m = int(spl[1].split(':')[1])
- s = int(spl[1].split(':')[2])
- alc[id] = h*3600 + m*60 + s
- bot.send_message(id, "Alarm clock set.")
- elif text == "clear":
- alc[id] = 999999
- bot.send_message(id, "Alarm clock deleted.")
- def checkTime():
- while True:
- hms = datetime.now().strftime("%H %M %S").split(' ')
- currtime = int(hms[0]) * 3600 + int(hms[1]) * 60 + int(hms[2])
- for k in alc.keys():
- if currtime >= alc[k]:
- alc[k] += 10
- bot.send_message(k, "ALARM!!! ALARM!!! (text \"clear\" to stop the alarm)")
- timeThread = Thread(target = checkTime)
- timeThread.start()
- bot.polling(none_stop=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement