Scheduling execution of Python scripts at given time every day. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Scheduling execution of Python scripts at given time every day.

I made a newsletter script using python that generates a HTML source compatible with Email. I made another another python script to send this email. Now, I need to automate this email sending at, say, 7 AM everyday. I have tried using windows task scheduler. But it works only if my laptop is on at that time. Can anyone suggest any other way to do this?

12th Jul 2019, 3:25 AM
Vivek Sivaramakrishnan
Vivek Sivaramakrishnan - avatar
3 Answers
+ 2
If you don't want to depend on your laptop to be online, then the best thing to do would be to deploy it as an online service. There are websites where you can do this, even for free within certain limits. I suggest to check Heroku, they even have a scheduler service: https://elements.heroku.com/addons/scheduler
12th Jul 2019, 7:07 AM
Tibor Santa
Tibor Santa - avatar
+ 1
You can have the program run constantly and use the time module to schedule it. You use that script to excecute the command whenever the time arrives
12th Jul 2019, 6:55 AM
Trigger
Trigger - avatar
+ 1
import time import datetime import [modules you wrote] while True: if datetime.datetime.now().hours == 7: [run script] # loop every half-hour or so time.sleep(1800)
12th Jul 2019, 7:02 AM
Trigger
Trigger - avatar