Data API - Scheduling And Automatically Running A Python Script On Windows

A guide on how to automate the running of the python script generated within RotaMaster

Installing Python

To install Python on Windows, download and install the latest version of Python from https://www.python.org/downloads/windows/

Alternatively, use one of the following download links:

https://www.python.org/ftp/python/3.10.0/python-3.10.0.exe (32-bit)

https://www.python.org/ftp/python/3.10.0/python-3.10.0-amd64.exe (64-bit)

To find out whether you are running a 32-bit or 64-bit version of Windows, follow one of the following methods:

  • Control Panel (category view) > System and Security > System

or Control Panel (icons view) > System

    • Locate System type

  • Search for System informationin the start menu and open it

    • Locate System Type

      • If it shows x64-based PCthen download the 64-bit version of the Python installer. If it shows x86-based PC, download the 32-bit version.

Run the installation file once downloaded.

Note: When installing Python, make note of the install path. This will be needed later when setting up the scheduled task.

When prompted with the initial installation screen, press Install Now to use the default settings or Customize installation if you wish to change the installation location or other features.

Running a Python script manually

To run a Python script, locate the file and double-click to open it. This should run the script and save the JSON files in the file path specified when the script was generated.

Setting Up a Scheduled Task

Finding the Task Scheduler

First, find the Task Scheduler on your machine. This can be found in the following ways:

  • Search for task scheduler in the start menu

  • Go to Control Panel (category view)> System and Security > Schedule tasks

  • Go to Control Panel (category view) > System and Security > Administrative Tools or Control Panel (icons view) > Administrative Tools and select Task Scheduler

Creating a scheduled task

In the Task Scheduler window, find and click Create Basic Task.

    

In the first screen of the Create Basic Task Wizard, enter a name and description (optional) for the task. Press Next when done.

On the next screen, select when you want the task to run. 

Press Next and the following screen will then allow you to set when the task will start and how frequently it will run. Press Next when done.

On the next screen, leave selection as Start a program and press Next.

The next screen will set up running the Python file with the installed Python application. For the Program/script, enter the location of the python.exe file (found in the install path specified when installing Python).

e.g. C:\Users\{user}\AppData\Local\Programs\Python\Python310\python.exe

For Add arguments, enter the location of the .py file that you wish to run.

e.g. "C:\RM Data\{user}\Data API Python Script_041121_131255.py"

Note: quotation marks needed

On the final screen, verify the details and press Finish.

The Python script should now run at the set start time and will repeat for the set frequency. The JSON files will be created in the file path specified when the script was generated.