Ati Sanghera Portfolio

Data Scientist & Web Developer

Task Scheduler

This code automates Python file executions and GitHub commits.

The reason it was done this way was because I when I first made this page I used to host my website on GitHub Pages where backend is not allowed i.e. only static pages.

Python Script Run Automation

The first section is automation of a Python file.

Create a text file with the following:

:: The first line is to activate your virtual environment if you are using one.
I am using the base environment in Anaconda so I leave it blank
call C:/ProgramData/Anaconda3/condabin/activate.bat your-env-name

:: Load your Python version and run your .py file
{/* C:/ProgramData/Anaconda3/python.exe "./*.py" */}

:: It is good practice to deactivate your virtual environment
call C:/ProgramData/Anaconda3/condabin/deactivate.bat

Text can be added to the file if preceded with two colons: ::

Save the file and rename the extension to .bat

Add the file to the task scheduler by right clicking the Windows icon in the bottom left of your screen and clicking "Computer Management".

Click "Task Scheduler" in the left pane and then "Create Basic Task" in the right pane.

In the program script section, add the path to the bat file in double quotes: "path to bat file". Enter other options as preferred.

The bat file will now open the terminal as scheduled. Well done!

To open the terminal silently in the background, download the free program "nircmd" and in the program script section add: nircmd exec hide in front of the double quotes.

Github Commit Automation

This section deals with the automation of a GitHub commit.

Create a text file with the following:

:: Wait 120 sec for py files to run before activating this
timeout /t 120 /nobreak

cd C:/repository-location-on-local-drive

:: This code logs you into your GitHub and sets an expiry of 10 minutes on the credentials.
:: Replace your username and password below.
git config --global username password
git config --global credential.helper store
git config --global credential.helper 'cache --timeout 600'

:: Commits your files and pushes onto GitHub
git add *
git commit -m "New commit: %date:~-4% %date:~0,2%/%date:~3,2% - %time:~0,2%:%time:~3,2%"
git push
exit

Add this bat file into the task scheduler at the same location as the previous section.