Skip to content

PriceSmart Results Scraper #1092

PriceSmart Results Scraper

PriceSmart Results Scraper #1092

Workflow file for this run

# This workflow will install Python dependencies, run tests, and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: PriceSmart Results Scraper
on:
schedule:
- cron: "0 8 * * *" # Runs daily at 4 AM Trinidad time (8 AM UTC)
workflow_dispatch: # Allows manual trigger from GitHub Actions tab
permissions:
contents: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Set Time Zone
run: |
export TZ="America/Port_of_Spain"
shell: bash
- name: execute py script # run main.py
run: python "pricesmart_scraper.py"
- name: Verify database file exists
run: |
if [ ! -f "Database/PriceSmart_Products_Database.db" ]; then
echo "Error: Database file not found after scraper run"
exit 1
fi
echo "Database file found, proceeding with sync..."
- name: Sync to Supabase
run: |
echo "=========================================="
echo "Starting Supabase sync..."
echo "=========================================="
python "supabase_sync.py"
echo "=========================================="
echo "Supabase sync completed successfully"
echo "=========================================="
env:
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_SERVICE_ROLE_KEY: ${{ secrets.SUPABASE_SERVICE_ROLE_KEY }}
SUPABASE_DB_PASSWORD: ${{ secrets.SUPABASE_DB_PASSWORD }}
continue-on-error: false
- name: Clear Old Analysis in README
run: |
sed -i '/{{analysis_placeholder}}/q' README.md
shell: bash
- name: Read Analysis File
id: read-analysis
run: |
analysis=$(cat analysis_report.html)
echo "::set-output name=analysis::$analysis"
- name: Update README with Analysis
run: |
analysis=$(cat analysis_report.html)
sed -i "/{{analysis_placeholder}}/r analysis_report.html" README.md
shell: bash
- name: Commit and Push
run: |
git config --global user.name ${{ secrets.GitName }}
git config --global user.email ${{ secrets.GitEmail }}
git add . # Add your database file
git add README.md # Add the updated README file
git commit -m "Update README with analysis" # Commit changes
# Set up authentication using the GitHub token secret
git remote set-url origin "https://github.com/$GITHUB_REPOSITORY"
git config credential.helper "store --file=.git-credentials"
echo "https://$GH_TOKEN@github.com" > .git-credentials
git pull
# Push changes using the GitHub token
git push
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}