import re, os, json

base = os.path.dirname(os.path.abspath(__file__))
html = open(os.path.join(base, "index_main.html"), encoding="utf-8").read()

cands = [
    "harvard-bus-eco-phd",
    "brown-scm-cs",
    "umich-ece-ms",
    "usc-stats-ms",
    "berkeley-maiml",
    "umich-hds-ms",
    "umich-msi",
    "umich-biostat-ms",
]

blocks = re.findall(r'\{id:"([^"]+)"([\s\S]*?)(?=\{id:"|\n\];)', html)
bm = {bid: body for bid, body in blocks}

for c in cands:
    if c not in bm:
        print(c, "NOT FOUND in PROGRAMS")
        continue
    body = bm[c]
    def g(k):
        m = re.search(k + r':"([^"]*)"', body)
        return m.group(1) if m else ""
    lvl = re.search(r'lvl:"([^"]*)"', body)
    url = g("url")
    en = g("en")
    n = g("n")
    deg = g("deg")
    lvlv = lvl.group(1) if lvl else "?"
    det = os.path.join(base, "details", os.path.basename(url)) if url else ""
    disk = os.path.exists(det) if det else False
    print(f"== {c} | lvl={lvlv} deg={deg}")
    print(f"   n={n}")
    print(f"   en={en}")
    print(f"   url={url} disk={disk}")

# CATD 对应检查
catd = re.search(r'const CATD\s*=\s*\[(.*?)\];', html, re.S)
if catd:
    for c in cands:
        hits = [ln for ln in catd.group(1).split("],") if c in ln]
        print(f"CATD {c}: {len(hits)} hit")
