PYPI Schedule

·

2 min read

Now that I have my code to scrape a webpage or three of all of the interesting information. I thought to myself, how do I automate this just a little bit further?

I want to start up the pc in the morning, set up the code to run at intervals during the day, specific times, thus saving me the worry of forgetting to run the code whilst doing other important tasks.

The interesting information changes depending on the time of day and capturing these changes is what I am after. In comes the python package Schedule on pypi.org and it is exactly what I needed.

The examples shown in the documentation are simple, of course, I didn't think a quick copy and paste into my code would make the magic happen., but the process of setting this up was simply the case of creating a new scheduler module and all was good in the world.

# scheduler.py
import schedule
import time
from sys import exit

 # import in the function/s I want to schedule
from module_to_run import main_function as mf 
from second_module_to_run import main_function as mf2

# Choose the selection - For the purpose of the blog I will use just this
schedule.every().day.at("08:45").do(mf2)

while True:
    schedule.run_pending()
    time.sleep(1)

exit()

I have only put in one of the schedules and there are a variety of options that I will be going through to find the best way to set this.

So now, the pc goes on, I open a terminal, activate the venv then run the scheduler module.
That is it, minimise the terminal window and get on with the many other things that take attention in work. Knowing when I go to the folder holding the web scrapes of that day they will be there. Automation for the better.

If you are interested in knowing more about Schedule you should look here at the examples within the official documentation.