diff options
| author | Yasutake Yohei <61961825+yasutakeyohei@users.noreply.github.com> | 2026-11-05 23:25:28 +0900 |
|---|---|---|
| committer | Yasutake Yohei <61961825+yasutakeyohei@users.noreply.github.com> | 2026-11-05 23:25:28 +0900 |
| commit | 6bcceb9dfc338daa539a4db1b10f9cae22522770 (patch) | |
| tree | baf9e2bc360eb470f8a7efb6df6ded065eebff58 /scripts/fetch-logoform-events.mjs | |
| parent | ff6202cf8f56dfd46fe108ea3bd0f9fe7edfbad7 (diff) | |
events: LoGoフォームの一覧を取得し事業承継セミナーの日程を修正
LoGoフォームの一覧APIを呼ぶスクリプトを追加した。18件を取得して
既存データと照合したところ、事業承継セミナーの日程が12月15日から
11月25日(水)の誤りだったため、市のページで確認して直した。
Diffstat (limited to 'scripts/fetch-logoform-events.mjs')
| -rw-r--r-- | scripts/fetch-logoform-events.mjs | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/scripts/fetch-logoform-events.mjs b/scripts/fetch-logoform-events.mjs new file mode 100644 index 0000000..f499d47 --- /dev/null +++ b/scripts/fetch-logoform-events.mjs @@ -0,0 +1,82 @@ +// LoGoフォーム(小平市)の手続き一覧を取得する。 +// +// LoGoフォームのページ自体は自動アクセス防止(TRUSTBANKの確認画面)で +// ブラウザから開けないことがある。一方、一覧のAPIは直接呼べる。 +// ただし Node の fetch では 403 になるため、curl を使って取得している。 +// +// 使い方: +// node scripts/fetch-logoform-events.mjs # イベント情報(procedure id 49006) +// node scripts/fetch-logoform-events.mjs 48668 # 電子申請(手続き一覧) +// node scripts/fetch-logoform-events.mjs 49006 --json +// +// procedure id は、手続きページの設定に "id" として入っている。 +// 2517(イベント情報)は 49006、666(電子申請)は 48668。 + +import { execFileSync } from 'node:child_process'; + +const DEFAULT_ID = '49006'; +const args = process.argv.slice(2); +const asJson = args.includes('--json'); +const procedureId = args.find((a) => /^\d+$/.test(a)) ?? DEFAULT_ID; + +const PAGE = procedureId === '48668' + ? 'https://logoform.jp/procedure/exdH/666' + : 'https://logoform.jp/procedure/exdH/2517'; + +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 curlArgs = [ + '-s', + '--max-time', + '30', + '-X', + 'POST', + '-H', + 'Content-Type: application/json', + '-H', + 'Accept: application/json', + '-H', + `Referer: ${PAGE}`, + '-H', + `User-Agent: ${UA}`, + // 空のオブジェクトで全件返る。page などの項目を足すと「不明な項目」で弾かれる。 + '-d', + '{}', + `https://logoform.jp/api/procedure/branch/detail/search/${procedureId}`, +]; + +let raw; +try { + raw = execFileSync('curl', curlArgs, { encoding: 'utf8', maxBuffer: 20 * 1024 * 1024 }); +} catch (error) { + console.error('curl の実行に失敗しました。curl が使えるか確認してください。'); + console.error(String(error).slice(0, 300)); + process.exit(1); +} + +let data; +try { + data = JSON.parse(raw); +} catch { + console.error('JSONとして読めませんでした(自動アクセス防止の画面が返っている可能性があります)。'); + console.error(raw.slice(0, 300)); + process.exit(1); +} + +const items = Array.isArray(data.items) ? data.items : []; + +if (asJson) { + console.log(JSON.stringify(items, null, 2)); + process.exit(0); +} + +console.log(`procedure_id=${procedureId} 件数=${items.length}`); +for (const item of items) { + const description = (item.description ?? '').replace(/\s+/g, ' ').trim(); + console.log( + `- [${item.category_name}] ${item.procedure_name}` + + (description ? `\n ${description.slice(0, 120)}` : '') + + `\n https://logoform.jp${item.form_url ?? ''}`, + ); +} |
