Collect AQI Data #498
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
# .github/workflows/collect_aqi.yml | |
name: Collect AQI Data | |
on: | |
schedule: | |
- cron: '0 * * * *' # Run every hour | |
workflow_dispatch: # Allow manual triggers | |
permissions: | |
contents: write # Add this line to grant write permissions | |
jobs: | |
collect: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.9' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install requests pandas | |
- name: Run AQI collector | |
env: | |
OPENWEATHER_API_KEY: ${{ secrets.OPENWEATHER_API_KEY }} | |
run: python aqi_collector.py | |
- name: Commit and push if changed | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
git add data/aqi_data.csv | |
git diff --quiet && git diff --staged --quiet || (git commit -m "Update AQI data [skip ci]" && git push origin main) | |
- name: Preserve docs folder | |
run: | | |
if [ -d docs ]; then | |
cp -r docs/ docs_backup/ | |
fi | |
# ... existing commit/push step ... | |
- name: Restore docs folder | |
run: | | |
if [ -d docs_backup ]; then | |
cp -r docs_backup/ docs/ | |
rm -rf docs_backup/ | |
fi |