name: Fetch Fan

on:
  workflow_dispatch:
    
  schedule:
    - cron: '5 */4 * * *'

jobs:
  run_python_script:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout code
      uses: actions/checkout@v2

    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: 3.x

    - name: Install dependencies
      run: pip install requests

    - name: Run Python script
      run: python ./fan.py

    - id: check
      name: Check for changes
      run: |
        if git diff-index --quiet HEAD --; then
          echo "No changes detected. Skipping commit."
          exit 0
        fi
        git config --global user.name "GitHub Actions"
        git config --global user.email "actions@github.com"
        git add .
        git commit -m "update"

    - name: Push changes
      if: steps.check.conclusion == 'success'
      uses:  ad-m/github-push-action@master
      with:
         # github_token: ${{ secrets.TOKEN }}
         branch: main