Air Quality - Pollutant Index - India
Tags: actionshackathon21, python, googlesheets, tableau
Published: 2021-11-24 18:40:28

This mini project shows the Air Quality Index (Industrial Air Pollution) from various locations in India in a Tableau Public dashboard.
The data is sourced from data.gov.in API using Python for cleaning & loading the data in Google Sheets. 
Data is updated daily (or manually) using GitHub Actions or AWS Lambda.

### My Workflow
#### GitHub Action "[run-python.yml](https://github.com/AdhirKirtikar/Air-Quality-Index-India-GitHub-Actions/blob/master/.github/workflows/run-python.yml)"
- Google credentials are stored in GitHub Actions Environment Secrets.
- data.gov.in API Key is also stored in GitHub Actions Environment Secrets.
- A GitHub Action is created that can run manually or on a schedule [12PM UTC (8PM SGT)].
- Python 3.9 is setup using [actions/setup-python@v2.3.0](https://github.com/actions/setup-python) and the pip packages are cached.
- Dependencies are installed using [py-actions/py-dependency-install@v2](https://github.com/marketplace/actions/python-dependency-installation)  based on requirements.txt (google auth, pygsheets & pandas).
- The Environment Secrets are exported to environment variables.
- Finally, the Python script is run with the environment variables passed as parameters.

### Submission Category: 
Wacky Wildcards
- I tried to use this workflow as a replacement / complement to the AWS Lambda function that processes the Python script at 8AM SGT.

### Yaml File or Link to Code
#### [run-python.yml](https://github.com/AdhirKirtikar/Air-Quality-Index-India-GitHub-Actions/blob/master/.github/workflows/run-python.yml)
```
# This is a basic workflow to help you get started with Actions

name: Run Python

# Controls when the action will run. 
on:
  schedule:
    # run at 12PM UTC (8PM SGT)
    - cron: '0 12 * * *'
  
  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # use environment (named as "env") defined in the GitHub repository settings
    environment: env

    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      -
        name: Checkout
        uses: actions/checkout@v2
      
      # Set up Python 3.9 environment and cache pip packages
      - 
        name: Setup Python 3.9
        uses: actions/setup-python@v2.3.0
        with:
          python-version: '3.9'
          cache: 'pip'
        # This action sets up a Python environment for use in actions by:
        #   optionally installing and adding to PATH a version of Python that is already installed in the tools cache.
        #   optionally caching dependencies for pip and pipenv.
      
      # Install dependencies mentioned in the requirements.txt
      - 
        name: Install dependencies
        uses: py-actions/py-dependency-install@v2
        # This GitHub Action installs Python package dependencies from a user-defined requirements.txt file path 
        # with pip, setuptools, and wheel installs/updates during execution. 
        # A Python package environment report is displayed at the end of Action execution.
        # Uses path requirements.txt and updates pip, setuptools, and wheel before the install.
      
      # Run a bash shell and store env secrets in parameters to pass to Python script
      -
        name: Get Parameters & Run Air Quality Index India Python script
        shell: bash
        env:
          GOVINAPIKEY: ${{ secrets.DATA_GOV_IN_API_KEY }}
          GDRIVEAPIKEY: ${{ secrets.GDRIVE_API_CREDENTIALS }}
        run: |
          python "Air Quality Index India.py" "$GOVINAPIKEY" "$GDRIVEAPIKEY"
```
#### Full repository is here:
{% github AdhirKirtikar/Air-Quality-Index-India-GitHub-Actions %}

### Additional Resources / Info
Tableau Public Dashboard that uses the data from the generated Google Sheets: "[Air Quality - Pollutant Index - India](https://public.tableau.com/views/AirQuality-PollutantIndex-India/PollutantIndexDashboard?:language=en-US&:display_count=n&:origin=viz_share_link)"