# -*- coding: utf-8 -*-
import io, sys, os, re, json, datetime
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
os.chdir(r"D:\work buddy\2026-11-05-14-15-52")
idx=open("index_main.html",encoding="utf-8").read()
seg=idx[idx.find("const PROGRAMS="):idx.find("const CATD=")]
plvl=re.findall(r'lvl:"([^"]+)"',seg)
master=plvl.count("m"); phd=plvl.count("d"); programs=len(plvl)
vd=re.search(r'const VERIFIED_DETAILS=new Set\(\[(.*?)\]\);',idx,re.S).group(1)
vd_n=len(re.findall(r'"([^"]+)"',vd))
det_n=len([f for f in os.listdir("details") if f.endswith(".html")])
mtime=datetime.datetime.fromtimestamp(os.path.getmtime("index_main.html")).strftime("%Y-%m-%d %H:%M:%S")
print("实测 programs",programs,"master",master,"phd",phd,"VD",vd_n,"details",det_n,"mtime",mtime)

b=json.load(open("_heartbeat_baseline.json",encoding="utf-8"))
b["updated_at"]=mtime; b["index_main_mtime"]=mtime
b["schools"]=36; b["programs"]=programs; b["programs_master"]=master; b["programs_phd"]=phd
b["catd"]=2676; b["dead_links"]=0; b["excluded_residue"]=0
b["vd_set"]=vd_n; b["details_html"]=det_n; b["node_check"]="exit 0"

new=[
 ("rice-mche-ms","details/rice-chemical-biomolecular-engineering.html","MChE"),
 ("rice-mcee-ms","details/rice-civil-environmental-engineering.html","MCEE"),
 ("rice-mmsne-ms","details/rice-materials-science-nanoengineering.html","MMSNE"),
 ("rice-mbe-ms","details/rice-bioengineering.html","MBE"),
 ("dartmouth-hds-ms","details/dartmouth-health-data-science.html","HDS"),
]
for _,det,_ in new:
    tag=det+" 浏览器实开待后端会话恢复后补核（六卡静态核对已通过）"
    if det not in b["pending_browser_check"]:
        b["pending_browser_check"].append(tag)

notes=[
 "Rice MChE（rice-mche-ms）：半核验入库。Chemical and Biomolecular Engineering 系，professional course-based non-thesis；方向能源可持续/材料工程/生物技术与生物制造/软物质与复杂流体/先进化工；Fall 12/31(Late 4/1)，Spring 10/1；EPMP 通用 GPA3.0+/3 推荐信/TOEFL90 IELTS7 Duolingo115，GRE optional；学分总数/学费待补。排除研究型 MS/PhD/第五年贯通/在线在职。",
 "Rice MCEE（rice-mcee-ms）：半核验入库。Civil and Environmental Engineering 系，professional non-thesis，30 学分含 2 学分 final project；方向 Civil/Environmental；Fall 1/15，Spring 11/1；EPMP 通用口径；学费待补。排除研究型 MS/PhD/在线在职。",
 "Rice MMSNE（rice-mmsne-ms）：半核验入库。Materials Science and NanoEngineering 系，non-thesis professional；方向先进制造/生物材料/碳纳米材料复合材料/计算材料科学；Fall 2/1，Spring 11/15；EPMP 通用口径；学分/学费待补。排除研究型 MS/PhD/在线在职。",
 "Rice MBE（rice-mbe-ms）：半核验入库。Bioengineering 系，non-thesis，full/part-time，工程或科学 BA/BS；方向 Applied Bioengineering / Global Medical Innovation；AB Fall 2/1(Priority)/4/15(Final) Spring 10/15，GMI Fall 1/31 无春；EPMP 通用口径；学分/学费待补。排除研究型 MS*/PhD、MBE/MD 双学位(UT Health)、PhD/MD(Baylor)、在线在职。",
 "Dartmouth MS HDS 在校版（dartmouth-hds-ms）：半核验入库。Geisel/Tdi；在校 12 个月，每班约 30-40 人，每次 4 门课，10 周 capstone；课程编程/生统/ML/AI，结构化非结构化/密集采集/大数据/影像/组学；SOPHAS 三轮 R1 12/1 R2 2/1 R3 4/15；GRE optional；非母语 TOEFL/IELTS/Duolingo（2 年内可豁免）；学费 $66,190/12 个月，merit 奖学金；无特定本科专业，建议编程+统计；推荐信数量/语言分数线待补。排除 Online MS（21 个月在线，15 门逐门修）。",
 "卡点待复核（本轮新增）：Duke MS Quantitative Financial Economics（duke-c76be69）2027-2028 申请季停招（No applications are being accepted），定性不纳入对外招生口径，不入库；Dartmouth Medical Informatics（tdi.dartmouth.edu）URLError 不可达；Rice Jones 商学院站 jonesbusiness.rice.edu URLError，MAcc/MFin/MEEcon 三条本轮无官方可达信息，留卡点；Rice MChE/MMSNE/MBE 学分总数、四条工程硕士学费费率 GA/招生页未单列待补；Dartmouth HDS 推荐信数量与语言分数线待补。",
]
for n in notes:
    if n[:40] not in " ".join(b["blocked_notes"]):
        b["blocked_notes"].append(n)

b["note"]=b["note"]+" 2026-11-19 心跳批量入库 5 条：Rice MChE/MCEE/MMSNE/MBE + Dartmouth HDS 在校版。重探：Rice CS 200；Stanford/USC Viterbi/JHU Eng 403；NYU GSAS 202 0B；UT Stat/Math 小字节 challenge 页待浏览器确认。"
json.dump(b,open("_heartbeat_baseline.json","w",encoding="utf-8"),ensure_ascii=False,indent=2)
print("基线已刷新：programs",b["programs"],"master",master,"phd",phd,"VD",vd_n,"details",det_n,"pending",len(b["pending_browser_check"]),"blocked",len(b["blocked_notes"]))
