# -*- coding: utf-8 -*-
import json, pathlib, sys, io
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=[")]
import re
for pid in ["nyu-ece", "nyu-ce", "nyu-cs", "nyu-appstat", "nu-cs", "cornell-cs-ms", "mcg-mma", "mcg-mmf", "duke-ece-ms", "usc-ece", "dartmouth-cs-ms", "wustl-mems-msme", "uchicago-stats", "uchicago-cam"]:
    r = rows.get(pid)
    if not r:
        print(pid, "NOT-IN-REPORT"); continue
    b = seg.find('{id:"%s"' % pid)
    piece = seg[b:b+900] if b >= 0 else ""
    ddl = re.search(r'ddl:"([^"]*)"', piece)
    tui = re.search(r'tui:"([^"]*)"', piece)
    url = re.search(r'url:"([^"]*)"', piece)
    print(pid, r["grade"], r["score"], r["m"], "| ddl=", ddl.group(1) if ddl else "?", "| tui=", tui.group(1) if tui else "?", "| url=", url.group(1) if url else "?")
