diff options
| author | Yasutake Yohei <61961825+yasutakeyohei@users.noreply.github.com> | 2026-09-22 15:04:15 +0900 |
|---|---|---|
| committer | Yasutake Yohei <61961825+yasutakeyohei@users.noreply.github.com> | 2026-09-22 15:04:15 +0900 |
| commit | 97b848288482ab3c6dd277c3ccdcca3eced7d52e (patch) | |
| tree | 975e083ea13e5a241f4af6192d6d0e9c6b0e1c88 /scripts/gen-sanpi-table.py | |
| parent | bf40363584d3d94cf5e76dbdac323246f2bf4a2b (diff) | |
sanpi.mdx ほか: 議案の賛否一覧の試作(下書き)を追加
小平市議会の「議案に対する各議員の賛否一覧」PDFから、会派ごと・議員ごとの賛否を抽出するスクリプト(scripts/)と、試作ページを追加した。ページは draft: true のため本番ビルドには含まれない(開発サーバーでのみ表示)。
Diffstat (limited to 'scripts/gen-sanpi-table.py')
| -rw-r--r-- | scripts/gen-sanpi-table.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/scripts/gen-sanpi-table.py b/scripts/gen-sanpi-table.py new file mode 100644 index 0000000..4cd926d --- /dev/null +++ b/scripts/gen-sanpi-table.py @@ -0,0 +1,52 @@ +import sys +import json + +sys.stdout.reconfigure(encoding="utf-8") + +with open(".sanpi-parsed.json", encoding="utf-8") as f: + data = json.load(f) + +members = [(int(c), g, n) for c, g, n in data["members"]] +rows = data["rows"] +for r in rows: + r["votes"] = {int(k): v for k, v in r["votes"].items()} + +# 会派ごとにまとめる(全行で一致していれば1列、分かれていれば議員ごとの列) +groups = {} +for col, g, n in members: + groups.setdefault(g, []).append((col, n)) + +cols = [] # (見出し, [(col, name)]) +for g, ms in groups.items(): + if len(ms) == 1: + cols.append((f"{g} {ms[0][1]}", ms)) + continue + same = True + for r in rows: + vals = {r["votes"].get(c) for c, _ in ms} + vals = {v for v in vals if v in ("〇", "○", "×")} # 表決に加わらない議員は除外 + if len(vals) > 1: + same = False + break + if same: + cols.append((g, ms)) + else: + # 安竹の列は常に表示しつつ、分かれた会派は議員ごとに + for c, n in ms: + cols.append((f"{n}({g})", [(c, n)])) + +print("| 議案 | 議決結果 | " + " | ".join(h for h, _ in cols) + " |") +print("|---|---|" + "---|" * len(cols)) +for r in rows: + cells = [] + for _, ms in cols: + vals = [r["votes"].get(c, "") for c, _ in ms] + real = {v for v in vals if v in ("〇", "○", "×")} + if len(real) == 1: + cells.append(next(iter(real))) + elif not real: + cells.append("—") + else: + cells.append("/".join(v or "—" for v in vals)) + no = r["番号"] or "" + print(f"| {no} {r['件名'][:40]} | {r['議決結果']} | " + " | ".join(cells) + " |") |
