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) + " |")