82 lines
2.6 KiB
YAML
82 lines
2.6 KiB
YAML
name: Scheduled Calendar Scraping
|
|
|
|
on:
|
|
schedule:
|
|
- cron: '0 0 * * *' # Runs daily at midnight UTC
|
|
workflow_dispatch:
|
|
inputs:
|
|
year:
|
|
description: 'Year to scrape (optional, defaults to current BS year)'
|
|
required: false
|
|
type: string
|
|
|
|
permissions:
|
|
contents: write
|
|
|
|
jobs:
|
|
scrape:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
token: ${{ secrets.PAT_TOKEN }}
|
|
fetch-depth: 0 # needed for pushes
|
|
|
|
- name: Install uv
|
|
uses: astral-sh/setup-uv@v5
|
|
|
|
- name: Install Python 3.13
|
|
run: uv python install 3.13
|
|
|
|
- name: Determine current Nepali year and run scraper
|
|
run: |
|
|
set -e # stop on errors
|
|
|
|
MANUAL_YEAR="${{ github.event.inputs.year }}"
|
|
|
|
if [ -n "$MANUAL_YEAR" ]; then
|
|
echo "Using manually specified year: $MANUAL_YEAR"
|
|
uv run python -- scraper.py "$MANUAL_YEAR" --dir
|
|
else
|
|
# Get current AD date components
|
|
AD_YEAR=$(date +%Y)
|
|
AD_MONTH=$(date +%-m) # remove leading zero
|
|
AD_DAY=$(date +%-d)
|
|
|
|
# Calculate approximate BS year
|
|
BS_YEAR=$((AD_YEAR + 56))
|
|
if [ "$AD_MONTH" -gt 4 ] || ([ "$AD_MONTH" -eq 4 ] && [ "$AD_DAY" -ge 14 ]); then
|
|
BS_YEAR=$((BS_YEAR + 1))
|
|
fi
|
|
echo "Current Nepali Year (approx): $BS_YEAR"
|
|
|
|
# Scrape current year
|
|
uv run python -- scraper.py "$BS_YEAR" --dir
|
|
|
|
# Scrape next year if within first 15 days of BS New Year
|
|
if [ "$AD_MONTH" -eq 4 ] && [ "$AD_DAY" -ge 14 ] && [ "$AD_DAY" -le 28 ]; then
|
|
NEXT_YEAR=$((BS_YEAR + 1))
|
|
echo "Near New Year, also scraping next year: $NEXT_YEAR"
|
|
uv run python -- scraper.py "$NEXT_YEAR" --dir
|
|
fi
|
|
fi
|
|
|
|
- name: Commit and push changes using PAT
|
|
env:
|
|
PAT_TOKEN: ${{ secrets.PAT_TOKEN }}
|
|
run: |
|
|
git config --global user.name "github-actions[bot]"
|
|
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
|
|
git add data/
|
|
|
|
# Commit only if there are changes
|
|
git diff-index --quiet HEAD || git commit -m "Automated update of Nepali calendar data"
|
|
|
|
# Pull latest changes to avoid conflicts
|
|
git pull --rebase origin main || true
|
|
|
|
# Push using PAT and set upstream
|
|
git push --set-upstream https://x-access-token:${PAT_TOKEN}@github.com/${GITHUB_REPOSITORY}.git HEAD:main
|