# -*- 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=[
 ("usc-ads-ms","details/usc-c05e87f.html","MS Applied Data Science"),
 ("usc-cse-ms","details/usc-c529da9.html","MS Cyber Security Engineering"),
 ("usc-hds-ms","details/usc-cfee36b.html","MS Healthcare Data Science"),
 ("usc-ce-ms","details/usc-c191471.html","MS Computer Engineering"),
 ("usc-ai-ms","details/usc-c6e9f6d.html","MS CS - Artificial Intelligence track"),
]
for _,det,_ in new:
    tag=det+" 浏览器实开待后端会话恢复后补核（六卡静态核对已通过）"
    if det not in b["pending_browser_check"]:
        b["pending_browser_check"].append(tag)

notes=[
 "USC MS Applied Data Science（usc-ads-ms）：已核验入库。Viterbi Informatics，32 学分、无论文、STEM OPT；Spring 10/15、Fall 12/15·1/15；2 推荐信 highly recommended，GRE not required；核心 DSCI 551/552/553（12 学分）+ 选修 5 门 20 学分；2025 平均报告薪资 $108,961（自愿调查）；排除 DEN@Viterbi 在线/在职版与 PhD 独立通道。",
 "USC MS Cyber Security Engineering（usc-cse-ms）：已核验入库。Viterbi Informatics，28 学分、无论文、STEM OPT；仅 Fall 12/15·1/15；推荐信 Optional，GRE not required；必修 CSCI 530/DSCI 519/523/529（16 学分）+ 至少 2 门（531/525/526/528）；2025 平均报告薪资 $156,000（自愿调查）；排除 DEN 在线版与 PhD。",
 "USC MS Healthcare Data Science（usc-hds-ms）：已核验入库。Keck 医学院 × Viterbi 联合学位，32 学分、无论文、STEM OPT；仅 Fall 12/15·1/15；2 推荐信 highly recommended，GRE not required；核心 BME 527/528、DSCI 510/549/550（20 学分）+ DS 至少 1 + Health 至少 1；2025 未提交平均薪资不臆造；排除 DEN 在线版、PhD 与纯临床执业学位。",
 "USC MS Computer Engineering（usc-ce-ms）：已核验入库。Viterbi ECE 系，28 学分、Thesis option 可选不保证、STEM OPT；Spring 10/15、Fall 12/15·1/15；推荐信 Optional，GRE not required；≥20 学分 CE 课，Architecture/Networks/VLSI-CAD 至少跨两方向；2025 平均报告薪资 $134,985（自愿调查）；与 MS ECE 总览页区分；排除 DEN 在线版与 PhD。",
 "USC MS CS - Artificial Intelligence（usc-ai-ms）：已核验入库。Viterbi CS 系，MS CS 下 AI specialized track，32 学分、无论文、STEM OPT；Spring 10/15、Fall 12/15·1/15；推荐信 Optional，GRE not required；官网未单列 AI track 必修课程代码，按 MS CS 框架修读；2025 平均报告薪资 $129,667（自愿调查）；官网明示本项目不通过 DEN 提供在线版；与 MS CS 总览页区分；排除 PhD。",
]
for n in notes:
    if n[:40] not in " ".join(b["blocked_notes"]):
        b["blocked_notes"].append(n)

b["note"]=b["note"]+" 2026-11-18 心跳批量入库 5 条 USC：Applied Data Science（details/usc-c05e87f.html）、Cyber Security Engineering（details/usc-c529da9.html）、Healthcare Data Science（details/usc-cfee36b.html）、Computer Engineering（details/usc-c191471.html）、CS-AI track（details/usc-c6e9f6d.html）。重探：Stanford/USC/Rice 系站仍 200；JHU Eng 403、NYU GSAS 202 空响应仍不可取正文；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"]))
