From f7240a325c5647e2f3fb46a81ed51bef51b2730b Mon Sep 17 00:00:00 2001
From: Yasutake Yohei <61961825+yasutakeyohei@users.noreply.github.com>
Date: Tue, 17 Nov 2026 23:28:34 +0900
Subject: fetch-city-events.mjs:
市ホームページのイベント一覧を走査するスクリプトを追加
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
「/event/」の各イベントから開催日を取り出し、今日以降のものを一覧表示する。--missing を付けると予定データに無いものを抽出できる(題名の先頭6文字で照合するため、表記ゆれによる誤検出はある)。
---
scripts/fetch-city-events.mjs | 76 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 76 insertions(+)
create mode 100644 scripts/fetch-city-events.mjs
diff --git a/scripts/fetch-city-events.mjs b/scripts/fetch-city-events.mjs
new file mode 100644
index 0000000..50ad72d
--- /dev/null
+++ b/scripts/fetch-city-events.mjs
@@ -0,0 +1,76 @@
+// 小平市ホームページのイベント一覧(/event/)から、これからのイベントを取り出す。
+//
+// 使い方:
+// node scripts/fetch-city-events.mjs # 今日以降のイベントを一覧
+// node scripts/fetch-city-events.mjs --missing # 予定データに無いものだけ表示
+// node scripts/fetch-city-events.mjs --days 30 # 何日先まで見るか
+//
+// ページは各イベントが
+//
…
+// …
+// の形で並んでいる。日付は data-date_start(開始日時)を使う。
+import { execFileSync } from 'node:child_process';
+import { readFileSync } from 'node:fs';
+
+const UA =
+ 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36';
+
+const args = process.argv.slice(2);
+const onlyMissing = args.includes('--missing');
+const daysIndex = args.indexOf('--days');
+const days = daysIndex >= 0 ? Number(args[daysIndex + 1]) : 120;
+
+const html = execFileSync(
+ 'curl',
+ ['-s', '--max-time', '60', '-A', UA, 'https://www.city.kodaira.tokyo.jp/event/'],
+ { encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 },
+);
+
+const pad = (n) => String(n).padStart(2, '0');
+const toKey = (d) => `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
+const now = new Date();
+const todayKey = toKey(now);
+const limit = new Date(now);
+limit.setDate(limit.getDate() + days);
+const limitKey = toKey(limit);
+
+const items = [];
+for (const block of html.split('class="event_info"').slice(1)) {
+ const link = block.match(/