# -*- 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-csds-ms","details/usc-c330039.html","MS CS - Data Science"),
 ("usc-csgd-ms","details/usc-c8c3147.html","MS CS - Game Development"),
 ("usc-csse-ms","details/usc-cf13c48.html","MS CS - Scientists and Engineers"),
 ("usc-ecehm-ms","details/usc-c29e433.html","MS ECE - Hardware Systems for ML"),
 ("usc-ecemlds-ms","details/usc-c8eb349.html","MS ECE - Machine Learning and Data Science"),
]
for _,det,_ in new:
    tag=det+" 浏览器实开待后端会话恢复后补核（六卡静态核对已通过）"
    if det not in b["pending_browser_check"]:
        b["pending_browser_check"].append(tag)

notes=[
 "USC MS CS - Data Science（usc-csds-ms）：已核验入库。Thomas Lord CS 系，32 学分、无论文、STEM OPT；Spring 10/15、Fall 12/15·1/15；推荐信 Optional，GRE not required；必修 CSCI 561/570/585（12 学分）+ 分组选修；2025 平均报告薪资 $166,000（基于 1 份提交，自愿调查）；排除 DEN@Viterbi 在线/在职版与 PhD 独立通道。",
 "USC MS CS - Game Development（usc-csgd-ms）：已核验入库。Thomas Lord CS 系，32 学分、无论文、STEM OPT；仅 Fall 12/15·1/15；推荐信 Optional，GRE not required；官网项目页未单列必修课程代码，方向 infrastructure/cognition & games/immersion/serious games；2025 平均报告薪资 $87,100（自愿调查）；排除 DEN 在线版与 PhD。",
 "USC MS CS - Scientists and Engineers（usc-csse-ms）：已核验入库。Thomas Lord CS 系，37 学分、无论文、STEM OPT；面向工程/科学学士、CS 背景有限者；录取后不能转入其他 MS CS 方向；Spring 10/15、Fall 12/15·1/15；推荐信 Optional，GRE not required；先修 CSCI 455，基础 EE 457/450 二选一 + CSCI 402，方向选修 500-600 级 CS；2025 平均报告薪资 $141,056；Top Employers Amazon/Bytedance/Meta/TikTok；排除 DEN 在线版与 PhD。",
 "USC MS ECE - Hardware Systems for Machine Learning（usc-ecehm-ms）：已核验入库。Ming Hsieh ECE 系，32 学分、Thesis option 可选不保证、STEM OPT；仅 Fall 12/15·1/15；推荐信 Optional，GRE not required；官网项目页未单列课程代码，方向 ML 硬件加速器设计/性能能耗分析/云端 ML 系统；官网项目页未披露平均报告薪资与雇主样本，留空不臆造；排除 DEN 在线版与 PhD。",
 "USC MS ECE - Machine Learning and Data Science（usc-ecemlds-ms）：已核验入库。Ming Hsieh ECE 系，32 学分、Thesis option 可选不保证、STEM OPT；Spring 10/15、Fall 12/15·1/15；推荐信 Optional，GRE not required；官网项目页未单列课程代码；2025 平均报告薪资 $136,400（自愿调查）；排除 DEN 在线版与 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：CS-Data Science（details/usc-c330039.html）、CS-Game Development（details/usc-c8c3147.html）、CS-Scientists and Engineers（details/usc-cf13c48.html）、ECE-Hardware Systems for ML（details/usc-c29e433.html）、ECE-ML and Data Science（details/usc-c8eb349.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"]))
