# -*- coding: utf-8 -*-
import json, re, sys, io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8", errors="replace")
P = r"D:\work buddy\2026-11-05-14-15-52\index_main.html"
t = open(P, encoding="utf-8").read()
seg = t[t.index("const PROGRAMS=["):t.index("const CATD=[")]
blocks = re.split(r'(?=\{id:")', seg)[1:]
def get(b, k):
    m = re.search(k + r':"((?:[^"\\]|\\.)*)"', b)
    return m.group(1) if m else ""
meta = {get(b, "id"): {"disc": get(b, "disc"), "url": get(b, "url"), "n": get(b, "n")} for b in blocks}
d = json.load(open(r"D:\work buddy\2026-11-05-14-15-52\_density_report.json", encoding="utf-8"))
hot = ["cs", "ee", "fin", "econ", "ba", "ds", "stat", "mech", "bio", "mgmt"]
schools = ["cornell", "nyu", "up", "ucsd", "vanderbilt", "gatech", "uchicago", "jhu", "usc", "rice", "emory", "notre", "cmu", "umich", "harvard", "col", "dartmouth", "brown", "uw", "berkeley", "ucla"]
rows = [r for r in d["rows"] if r["grade"] != "A" and r["score"] >= 7 and meta.get(r["id"], {}).get("disc") in hot]
for s in schools:
    sub = [r for r in rows if r["s"] == s]
    if not sub:
        continue
    sub.sort(key=lambda r: (-r["score"], -r["m"]["chars"]))
    print("###", s, len(sub))
    for r in sub[:6]:
        m = r["m"]
        print(f"  {r['score']} d={meta[r['id']]['disc']:5s} {r['id']:32s} c{m['cards']} ch{m['chars']} cd{m['codes']} mo{m['money']} dt{m['dates']} ext{m['ext_links']} | {r['n'][:26]}")
