How to setup github actions to run my python script on schedule?

I have a Github repo which analyzes data of COVID-19 cases from an api which updates everyday.

I have run.py script which clones the data but I don’t know how to setup github actions to run the script daily(automaticaly) so that data gets updated daily.

And one more thing I also want to export my Analysis.ipnb as index.html daily at the same time.

I don’t have any idea how to setup github actions to achive above tasks

Github Repo 

1 Like

Hi @piyushke ,

Thank you for being here! To answer your query:

  1. You need to create a workflow yaml, doc here: https://help.github.com/en/actions/configuring-and-managing-workflows/configuring-a-workflow#creating-a-workflow-file

  2. In the yaml, set ‘schedule’ event. Details here. code sample as below:

    name: py
    
    on:
      schedule:
        - cron: "0 0 * * *" #runs at 00:00 UTC everyday
    
    jobs:
      build:
        runs-on: ubuntu-latest
    
        steps:
          - name: checkout repo content
            uses: actions/checkout@v2 # checkout the repository content to github runner.
          - name: setup python
            uses: actions/setup-python@v2
            with:
              python-version: 3.8 #install the python needed
          - name: execute py script # run the run.py to get the latest data
            run: |
              python run.py
            env:
              key: ${{ secrets.key }} # if run.py requires passwords..etc, set it as secrets
          - name: export index
            .... # use crosponding script or actions to help export.

Thanks.

Hi @piyushke,

May I know where is you store the run.py file? Is it under github/workflow folder?

you can write a path ./scripts/run.py or either put it on the main folder. For example:

run: |
./scripts/run.py