Search code examples
pythonseleniumherokuprocfile

How to make a python script to run only on specific time on Heroku?


I have a python script(Do something on with selenium & send the result to my what'sapp [Used Twilio API]) and I hosted it on Heroku & scheduled to run one time per day. It runs on scheduled time as expected but it also runs on other time as well(more than 6 times per day). I don't want to run it other than scheduled time. How can I make it run only on scheduled time?

Procfile:

web: python my_script.py

Apart from that, I have requirements.txt & my_script.py in my directory.


Solution

  • You can use the time module and the while loop to check whether the current time is equal to the time that you want.

    from time import gmtime, strftime
    desired_time = '13:28'
    while True:
        if strftime("%H:%M", gmtime()) == desired_time:
            main()