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
Solution 1:
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()
Solution 2:
The answer provided might be the simplest possible option. Here's what I used in my personal project.
You can use APScheduler, to schedule the task to run at an interval.
from apscheduler.schedulers.background import BackgroundScheduler
def start():
scheduler = BackgroundScheduler()
scheduler.add_job(my_logger, 'interval', seconds=3)
scheduler.start()
Post a Comment for "How To Make A Python Script To Run Only On Specific Time On Heroku?"