crawler.yml 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. name: Hot News Crawler
  2. on:
  3. schedule:
  4. - cron: '*/50 * * * *' # 每50分钟运行一次
  5. workflow_dispatch:
  6. # 添加权限设置
  7. permissions:
  8. contents: write
  9. jobs:
  10. crawl:
  11. runs-on: ubuntu-latest
  12. steps:
  13. - name: Checkout repository
  14. uses: actions/checkout@v3
  15. - name: Set up Python
  16. uses: actions/setup-python@v4
  17. with:
  18. python-version: '3.9'
  19. - name: Install dependencies
  20. run: |
  21. python -m pip install --upgrade pip
  22. pip install requests pytz
  23. - name: Create frequency_words.txt if not exists
  24. run: |
  25. if [ ! -f frequency_words.txt ]; then
  26. echo "Creating empty frequency_words.txt file"
  27. touch frequency_words.txt
  28. fi
  29. - name: Run crawler
  30. env:
  31. FEISHU_WEBHOOK_URL: ${{ secrets.FEISHU_WEBHOOK_URL }}
  32. GITHUB_ACTIONS: true
  33. run: python main.py
  34. - name: Commit and push if changes
  35. run: |
  36. git config --global user.name 'GitHub Actions'
  37. git config --global user.email 'actions@github.com'
  38. git add -A
  39. git diff --quiet && git diff --staged --quiet || (git commit -m "Auto update by GitHub Actions at $(TZ=Asia/Shanghai date)" && git push)