Scheduling in Python
In this article, I’ll show you how to automate python to run functions for you at certain times. It is easier than you may think and can be done fairly quickly. Python comes with a built in sched library, but I used the schedule library.
First pip install schedule. This can be done in your Jupyter notebook or your terminal. In your terminal you do not need to include the ‘!’.
Let’s say for example you want to schedule your function to run every Tuesday at 9 A.M. and 10 A.M. Now that you have the schedule library, you can do that. In this example, my function is ‘get_info’. When you do this, insert the name of your function where the name of my function is.
You can also schedule a function to run every few minutes.
One thing to keep in mind is schedule will only work if your local server is active. This means you have to keep your computer open, not in sleep mode, and definitely not turned off. I’ve found closing my laptop has prevented the function from running, so make sure your local server is active when performing this. Currently, I am using the schedule library to web-scrape stock information, but your function can do anything.
The full documentation of the scheduling library can be found here https://pypi.org/project/schedule/
Happy scheduling and I hope this helps.