Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/fetch.json.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Update AtCoder Problems JSON

on:
schedule:
# 毎週水曜 0:00 UTC(日本時間 9:00)
- cron: "0 0 * * 3"
workflow_dispatch: # 手動実行も可能

permissions:
contents: write # push 権限が必要

jobs:
update-json:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 22

- name: Install dependencies
run: npm install
working-directory: data

- name: Run fetch-json script
run: node data/fetch-json.mjs
working-directory: data

- name: Commit changes if updated
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add data/problems.json data/problem_models.json
if git diff --cached --quiet; then
echo "No changes in JSON files"
else
git commit -m "chore: update problems.json and problem_models.json"
git push
fi
working-directory: data
4 changes: 2 additions & 2 deletions backend/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ fn adjust_difficulty(difficulty: Option<i32>) -> Option<f64> {
pub async fn fetch_problem() -> Result<(Vec<Problem>, HashMap<String, ProblemModel>), Box<dyn Error + Send + Sync>> {
// カレントディレクトリ基準で src/data を指す
let mut problems_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
problems_path.push("src/data/problems.json");
problems_path.push("../data/problems.json");

let mut problem_models_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
problem_models_path.push("src/data/problem-models.json");
problem_models_path.push("../data/problem-models.json");

// ファイル読み込み
let problems_text = fs::read_to_string(problems_path)?;
Expand Down
1 change: 0 additions & 1 deletion backend/src/data/problems.json

This file was deleted.

37 changes: 37 additions & 0 deletions data/json_fetch.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { mkdir, writeFile, access } from "node:fs/promises";
import { constants } from "node:fs";

const DATA_DIR = "."; // 保存先ディレクトリ
const UA = "Mozilla/5.0 (atrp-updater; +https://example.com)";

const endpoints = [
["problems.json", "https://kenkoooo.com/atcoder/resources/problems.json"],
["problem_models.json", "https://kenkoooo.com/atcoder/resources/problem-models.json"],
];

async function ensureDir(dir) {
try {
await access(dir, constants.F_OK);
} catch {
await mkdir(dir, { recursive: true });
}
}

async function download([filename, url]) {
const res = await fetch(url, { headers: { "User-Agent": UA } });
if (!res.ok) {
throw new Error(`HTTP ${res.status} for ${url}`);
}

const arrBuf = await res.arrayBuffer();
const buf = Buffer.from(arrBuf);
await writeFile(`${DATA_DIR}/${filename}`, buf);
console.log(`Saved: ${DATA_DIR}/${filename}`);
}

(async () => {
await ensureDir(DATA_DIR);
for (const ep of endpoints) {
await download(ep);
}
})();
File renamed without changes.
1 change: 1 addition & 0 deletions data/problems.json

Large diffs are not rendered by default.