From 900332938d1fa006d9342c8f3c0bcef7592fcd42 Mon Sep 17 00:00:00 2001 From: hanyixuanten <105723997+hanyixuanten@users.noreply.github.com> Date: Mon, 20 Jul 2026 17:47:03 +0800 Subject: [PATCH] modify --- .github/workflows/deploy.yml | 36 ++++----- fetch_contests.py | 153 +---------------------------------- 2 files changed, 20 insertions(+), 169 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 691c9c8..059a259 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,16 +1,17 @@ -name: Update Contests & Deploy +name: Update Contests & Commit on: schedule: - # 每 30 分钟执行一次(可按需修改) - - cron: '*/30 * * * *' - workflow_dispatch: # 允许手动触发 + - cron: '*/30 * * * *' # 每30分钟执行一次 + workflow_dispatch: # 允许手动触发 jobs: - build-and-deploy: + update: runs-on: ubuntu-latest + permissions: + contents: write # 允许 Actions 推送代码 steps: - - name: Checkout + - name: Checkout repository uses: actions/checkout@v4 - name: Setup Python @@ -21,20 +22,15 @@ jobs: - name: Install dependencies run: pip install requests beautifulsoup4 - - name: Create public directory - run: mkdir -p public - - name: Fetch contests run: python fetch_contests.py - - name: Copy index.html to public - run: cp index.html public/ # 如果 index.html 本来就在 public 内,则不需要此步 - - - name: Deploy to FTP server - uses: SamKirkland/FTP-Deploy-Action@v4.3.5 - with: - server: ${{ secrets.FTP_SERVER }} - username: ${{ secrets.FTP_USERNAME }} - password: ${{ secrets.FTP_PASSWORD }} - local-dir: ./public/ - server-dir: /public_html/contests/ # 改成你希望存放的目录 + - name: Commit and push if changed + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "actions@github.com" + git add contests.json + git diff --staged --quiet || ( + git commit -m "Update contests.json [skip ci]" + git push + ) \ No newline at end of file diff --git a/fetch_contests.py b/fetch_contests.py index 5cfe39b..51736de 100644 --- a/fetch_contests.py +++ b/fetch_contests.py @@ -1,146 +1,5 @@ -import requests -import json -import time -import re -from datetime import datetime, timedelta, timezone -from bs4 import BeautifulSoup +# ... 前面四个平台的抓取函数保持不变 ... -# ---------- 工具函数 ---------- -def now_ts(): - return int(time.time()) - -def parse_duration_to_end(start_ts, seconds): - return start_ts + seconds - -# ---------- Codeforces ---------- -def fetch_codeforces(): - url = "https://codeforces.com/api/contest.list?gym=false" - try: - resp = requests.get(url, timeout=15) - data = resp.json() - if data["status"] != "OK": - return [] - contests = [] - for c in data["result"]: - if c["phase"] == "BEFORE": - contests.append({ - "platform": "Codeforces", - "title": c["name"], - "start_time": c["startTimeSeconds"], - "end_time": c["startTimeSeconds"] + c["durationSeconds"], - "url": f"https://codeforces.com/contests/{c['id']}" - }) - return contests - except Exception as e: - print(f"Codeforces error: {e}") - return [] - -# ---------- AtCoder (使用 kenkoooo 的非官方 API) ---------- -def fetch_atcoder(): - url = "https://kenkoooo.com/atcoder/resources/contests.json" - try: - resp = requests.get(url, timeout=15) - data = resp.json() - contests = [] - now = now_ts() - for c in data: - start = c["start_epoch_second"] - if start > now: # 只展示未来赛事 - contests.append({ - "platform": "AtCoder", - "title": c["title"], - "start_time": start, - "end_time": start + c["duration_second"], - "url": f"https://atcoder.jp/contests/{c['id']}" - }) - return contests - except Exception as e: - print(f"AtCoder error: {e}") - return [] - -# ---------- USACO (解析官网) ---------- -def fetch_usaco(): - url = "http://www.usaco.org/index.php?page=contests" - try: - resp = requests.get(url, timeout=15) - soup = BeautifulSoup(resp.text, "html.parser") - # USACO 赛程通常在