# -*- coding: utf-8 -*-
import io, sys, os, re, json
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
B = r"D:\work buddy\2026-11-05-14-15-52"
htmltxt = open(os.path.join(B,"index_main.html"),encoding="utf-8").read()
scope = json.load(open(os.path.join(B,"scope_2027_top30.json"),encoding="utf-8"))

# 主文件 SCHOOLS id
schools = re.findall(r'\{id:"([^"]+)"', htmltxt)
have = set(schools)
geo_alias = {"georgetown":"geo"}
missing=[]
for s in scope["ranked_top30"]:
    sid = s["id"]
    if sid=="georgetown": sid="geo"
    if sid not in have: missing.append((s["id"],s["cn"]))
keep = [k["id"] for k in scope["outside_top30_keep"]]
print("主文件院校数:", len(schools))
print("Top30 覆盖:", 30-len(missing), "/30")
print("缺失:", missing)
print("榜外保留在库:", [k for k in keep if k in have], " 缺:", [k for k in keep if k not in have])

# CATD / PROGRAMS 计数
catd = re.findall(r'^\["[a-z]+",', htmltxt, re.M)
prog = re.findall(r'\{id:"p\d+"', htmltxt)
print("CATD 条目:", len(catd), " PROGRAMS 核验:", len(prog))
# 博士核验
doc = re.findall(r'deg:"(PhD|EdD|DrPH|DBA|DMA|JD|MD|DSc|DNSc|DO|DNP|EdS)"', htmltxt)
print("PROGRAMS 博士:", len([d for d in doc]))
