# -*- coding: utf-8 -*-
import json, pathlib, sys, io, re
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8", errors="replace")
BASE = pathlib.Path(r"D:\work buddy\2026-11-05-14-15-52")
rows = {r["id"]: r for r in json.load(open(BASE / "_density_report.json", encoding="utf-8"))["rows"]}
html = (BASE / "index_main.html").read_text(encoding="utf-8", errors="replace")
seg = html[html.index("const PROGRAMS=["):html.index("const CATD=[")]
ids = re.findall(r'\{id:"([^"]+)"', seg)
for pre in ("nyu-", "mcg-", "nu-", "cornell-", "duke-"):
    print("==", pre)
    for i in ids:
        if i.startswith(pre):
            r = rows.get(i)
            g = f"{r['grade']}{r['score']} c{r['m']['cards']}ch{r['m']['chars']}cd{r['m']['codes']}" if r else "NO-REPORT"
            b = seg.find('{id:"%s"' % i); piece = seg[b:b+800]
            nm = re.search(r'n:"([^"]*)"', piece)
            print(f"   {i:34s} {nm.group(1)[:34] if nm else '':36s} {g}")
