Weather Data Workflow #88
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Weather Data Workflow | |
on: | |
schedule: | |
- cron: '30 16 * * *' # 10:00 PM IST (IST is UTC+5:30, so subtract 5:30 for UTC) | |
workflow_dispatch: # Allows manual trigger from the GitHub UI | |
jobs: | |
update-weather-data: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.11 | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
- name: Run weather data processing | |
run: python main.py | |
env: | |
WEATHER_API_KEY: ${{ secrets.WEATHER_API_KEY }} | |
GSHEET_CONNECTION: ${{ secrets.GSHEET_CONNECTION }} | |
- name: Run Weather API | |
run: | | |
nohup uvicorn weather_api:app --host 0.0.0.0 --port 8000 & | |
sleep 10 # Give the server some time to start | |
curl http://127.0.0.1:8000/docs # Example API call to ensure it's running | |
env: | |
WEATHER_API_KEY: ${{ secrets.WEATHER_API_KEY }} | |
- name: Commit updated CSV and JSON files | |
run: | | |
git config --global user.name "github-actions" | |
git config --global user.email "github-actions@github.com" | |
git add datasets/WeatherData.csv datasets/WeatherData.json | |
git commit -m "Update weather data CSV and JSON files" | |
git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git HEAD:main | |
env: | |
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} # GitHub token to allow the push | |
- name: Update Google Sheets with the new data | |
run: python main.py | |
env: | |
WEATHER_API_KEY: ${{ secrets.WEATHER_API_KEY }} | |
GSHEET_CONNECTION: ${{ secrets.GSHEET_CONNECTION }} |