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()
vd = set(re.findall(r'"(details/[^"]+\.html)"', html))

expect = {
    "harvard-bus-eco-phd": "商业经济学博士（PhD）",
    "brown-scm-cs": "计算机科学硕士（ScM）",
    "umich-ece-ms": "电气与计算机工程硕士（MSE）",
    "usc-stats-ms": "统计学硕士（MS）",
    "berkeley-maiml": "人工智能与机器学习硕士（MAIML）",
    "umich-hds-ms": "健康数据科学硕士（MS）",
    "umich-msi": "信息学硕士（MSI）",
    "umich-biostat-ms": "生物统计学硕士（MS）",
}
blocks = dict(re.findall(r'\{id:"([^"]+)"([\s\S]*?)(?=\{id:"|\n\];)', html))
for pid, nnew in expect.items():
    body = blocks[pid]
    n = re.search(r'n:"([^"]*)"', body).group(1)
    url = re.search(r'url:"([^"]*)"', body).group(1)
    disk = os.path.exists(os.path.join(base, url))
    invd = url in vd
    ok = (n == nnew and disk and invd)
    print(f"[{'OK' if ok else 'FAIL'}] {pid} | n={n} | url={url} | disk={disk} | VD={invd}")

# 确认无残留全英文旧串
for old in ["Business Economics (PhD)", "Computer Science ScM", "Electrical and Computer Engineering MS",
            "Statistics MS", "Master of AI and Machine Learning", "Health Data Science MS",
            "Information MS", "Biostatistics MS"]:
    print(f"残留 '{old}': {html.count(old)}")
