import re, os

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 = {
    "berkeley-biostat-ma": "生物统计学文学硕士（MA）",
    "brown-scm-biostat": "生物统计学硕士（ScM）",
    "umich-me-mse": "机械工程硕士（MSE）",
    "ucsd-mae-ms": "机械与航空航天工程硕士（MS）",
    "umich-robotics-ms": "机器人学硕士（MS）",
    "usc-apmath-ms": "应用数学硕士（MS）",
    "umich-bme-ms": "生物医学工程硕士（MSE）",
    "cornell-mps-aem": "应用经济学与管理专业硕士（MPS）",
}
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 ["Biostatistics MA", "Biostatistics ScM", "Mechanical Engineering MSE",
            "Mechanical and Aerospace Engineering MS", "Robotics MS",
            "Applied Mathematics MS", "Biomedical Engineering MSE",
            "Applied Economics and Management (MPS)"]:
    print(f"残留 '{old}': {html.count(old)}")
