import re, os
base = os.path.dirname(os.path.abspath(__file__))
html = open(os.path.join(base, "index_main.html"), encoding="utf-8").read()
catd = re.search(r"const CATD\s*=\s*\[(.*?)\];", html, re.S).group(1)

# 已删占位不得在 CATD 残留
for url in ["details/ut-mscsm.html", "details/usc-me-em-dual.html"]:
    print(f"CATD 残留 {url}: {url in catd}")

# 保留条 CATD 行目录层中文名
for url in ["details/ut-c7a2833.html", "details/usc-me-emgmt-dual-ms.html"]:
    if url in catd:
        row = re.search(r'\["[^"]*","[^"]*","[^"]*","([^"]*)","[^"]*","[^"]*","[^"]*","' + re.escape(url) + r'"\]', catd)
        print(f"CATD 命中 {url}, 目录层n={row.group(1) if row else '?'}")
    else:
        print(f"CATD 无对应行 {url}")

# 本轮 6 条译名 CATD 归属
for url in ["details/berkeley-cbe-pdp.html", "details/ucsd-se-ms.html", "details/uva-se-ms.html",
            "details/ubc-mppga.html", "details/usc-hsme-ms.html", "details/usc-mnlm.html"]:
    print(f"CATD {'命中' if url in catd else '无行'} {url}")
