-2

How can i check the time in Python and run a command every day at the same time?

if datetime.time() == 17.30:
     bot.sendMessage(ChatID, "Message")

I found a lot in the Internet, but i didn't found something which really helped me. I like to check the hour and the minutes. Later it should be implimented into a TelegramBot, which should send a Message to a Group every day. So Crontab would not be so nice also a timer.

Thanks for helping

Ham man
  • 3
  • 2

1 Answers1

0

This is probably better handled with a cron job, but here's the code

import datetime.datetime

now_time = datetime.now()

If now_time.hour == 17 and now_time.minute == 30:

    #do something
Chris May
  • 582
  • 1
  • 4
  • 10