3.1 KiB
OI Contest Fetch
en/zh
Fetch programming contest schedules from several online judge platforms and export them as JSON files. The repository also includes a small PHP page that can read the generated JSON and display upcoming contests.
Supported Platforms
- Codeforces
- AtCoder
- UOJ
- Nowcoder
Output Files
Running the fetch script writes JSON files to the repository root:
contests.json: contests that have not ended yet, including upcoming and currently running contests.contests_all.json: contests that finished within the last 30 days.
Each contest item has this shape:
{
"platform": "AtCoder",
"title": "AtCoder Beginner Contest 468",
"start_time": 1784980800,
"end_time": 1784986800,
"status": "upcoming",
"url": "https://atcoder.jp/contests/abc468"
}
start_time and end_time are Unix timestamps in seconds. status can be one of:
finishedrunningupcoming
Requirements
- Python 3
- PHP 5.4 or newer, only if you want to use the page under
server/
Python packages:
pip install requests beautifulsoup4
Usage
Run the fetch script from the repository root:
python fetch_contests.py
After a successful run, the script prints counts similar to:
Total upcoming contests: 13
Total contests finished in last 30 days: 139
Web Page
server/index.php reads the public raw GitHub URLs for contests.json and contests_all.json, caches them locally for 5 minutes, and renders upcoming contests with a client-side countdown plus recently finished contests. The page detects the browser/system language and time zone, syncs them to cookies, and uses them for localized text and contest times on later page loads. Unsupported languages fall back to English.
If you deploy it yourself, update this constant in server/index.php if your repository path or branch changes:
define('JSON_URL', 'https://raw.githubusercontent.com/hanyixuanten/OI-contest-fetch/master/contests.json');
The cache files are written next to index.php as contests_cache.json and contests_all_cache.json, so the web server process needs write permission for the server/ directory.
Automation
A typical automation flow is:
- Run
python fetch_contests.pyon a schedule. - Commit the updated JSON files.
- Push them to GitHub.
- Let
server/index.phpread the latestcontests.jsonfrom GitHub raw content.
For GitHub Actions, install the Python dependencies before running the script.
Development Notes
AI coding agents and maintainers should follow AGENTS.md when changing providers, output contracts, workflow behavior, or documentation.
Notes
- AtCoder uses the AtCoder Problems API and falls back to the official AtCoder contest page for upcoming contests when needed.
- UOJ is parsed from its public contests page, including the timeanddate duration parameters used by contest links.
- Nowcoder is parsed from the embedded contest metadata on its VIP contest index page.
- Network or upstream API changes can temporarily reduce the number of fetched contests.