# -*- coding: utf-8 -*-
import io, sys, os, re, collections, json
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
os.chdir(r"D:\work buddy\2026-11-05-14-15-52")
t=open("index_main.html",encoding="utf-8").read()
s=t[t.find("const PROGRAMS="):t.find("const CATD=")]
print("total", len(re.findall(r'\{id:"', s)))
print("lvl", collections.Counter(re.findall(r'lvl:"([^"]+)"', s)))

new_ids=["up-datsai-mse","yale-stat-ma","cmu-mscs","mit-mfin","mit-mban"]
for nid in new_ids:
    m=re.search(r'\{id:"'+re.escape(nid)+r'",.*?\}', s)
    if m:
        chunk=m.group(0)
        det=re.search(r'url:"([^"]+)"',chunk)
        deg=re.search(r'deg:"([^"]+)"',chunk)
        stem=re.search(r'stem:(\d)',chunk)
        cls=re.search(r'test:\{cls:"([^"]*)"\}',chunk)
        print(nid,"|",deg.group(1) if deg else "?","|stem",stem.group(1) if stem else "?","|cls",repr(cls.group(1)) if cls else "?","|",det.group(1) if det else "?")
    else:
        print(nid,"NOT FOUND")

# 五张详情页静态核对：h1 / h2 数 / 外链
for det in ["details/up-c0e9103.html","details/yale-statistics.html","details/cmu-c2ee442.html","details/mit-finance.html","details/mit-business-analytics.html"]:
    p=os.path.join(det)
    if os.path.exists(p):
        h=open(p,encoding="utf-8").read()
        print(det,"bytes",len(h),"h2",h.count("<h2>"),"官网链接",h.count('target="_blank"'))
    else:
        print(det,"MISSING")
