# -*- 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 ""

disc = {get(b, "id"): get(b, "disc") 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"]
sel = [r for r in d["rows"] if r["grade"] != "A" and disc.get(r["id"]) in hot]
sel.sort(key=lambda r: (hot.index(disc[r["id"]]), -r["score"], -r["m"]["chars"]))
print("hot non-A:", len(sel))
for r in sel[:45]:
    m = r["m"]
    print(f"{r['score']} d={disc[r['id']]:5s} {r['s']:8s} {r['id']:34s} c{m['cards']} ch{m['chars']} cd{m['codes']} mo{m['money']} dt{m['dates']} ext{m['ext_links']} | {r['n'][:24]}")
