# -*- 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-eds-ms","details/usc-c97fb24.html","MS Environmental Data Science"),
 ("usc-mds-ms","details/usc-ce4fd5a.html","MS Mathematical Data Science"),
 ("usc-em-ms","details/usc-c32a6e0.html","MS Engineering Management"),
 ("usc-pde-ms","details/usc-cc9187d.html","MS Product Development Engineering"),
 ("usc-bio-ms","details/usc-c568b0a.html","MS Biostatistics"),
]
for _,det,_ in new:
    tag=det+" 浏览器实开待后端会话恢复后补核（六卡静态核对已通过）"
    if det not in b["pending_browser_check"]:
        b["pending_browser_check"].append(tag)

notes=[
 "USC MS Environmental Data Science（usc-eds-ms）：已核验入库。Viterbi Data Science × Dornsife Environmental Studies Program 联合，32 学分、Thesis 不可用、STEM OPT；仅 Fall 12/15·1/15；推荐信 2 highly recommended，GRE not required；方向气候变化/水空气污染/政策/陆地水生生态/生物多样性/遥感，Wrigley Institute PBL；2025 平均薪资 None Submitted 不臆造；雇主 Albatross America/Impending Bloom/Reverse Logistics/Stealth Startup/Trussell Technologies，CPT 实习 California Air Resources Board；本项目 not available on DEN，排除在线版与 PhD。",
 "USC MS Mathematical Data Science（usc-mds-ms）：已核验入库。Dornsife 数学系，32 学分、MATH 590 ≥1 + summative report，3–4 学期（1.5–2 年）；官网未标注 STEM，stem:0；Fall 3/30、Spring 10/15；2 推荐信 + SOP + CV + 官方成绩单 + 英语成绩，GRE not required；先修多元微积分/线代/概率，推荐统计/优化/Python/R；核心 MATH 447/546/549/550 + PHYS 515（19 units）+ 选修 12；学费/申请费/语言最低分/薪资项目级未公布留空；排除 PhD，国际生须全日制 ≥8 units。",
 "USC MS Engineering Management（usc-em-ms）：已核验入库。Viterbi ISE 系（MSEMT），28 学分、Thesis option 可选不保证、STEM OPT；Spring 10/15、Fall 12/15·1/15；推荐信 3 highly recommended，GRE not required；方向技术项目领导/团队与工程职能管理/经济决策/技术创业，不专门聚焦 ISE；2025 平均报告薪资 $109,844（自愿调查）；雇主 ABB/AMD/Apple/Boeing/Boehringer Ingelheim/Cummins/FedEx/HRL/Intuitive Surgical/Maersk 等；排除 DEN 在线版与 PhD。",
 "USC MS Product Development Engineering（usc-pde-ms）：已核验入库。Viterbi Aerospace & Mechanical Engineering × Epstein ISE 联合，28 学分、Thesis option 可选不保证、STEM OPT；Spring 10/15、Fall 12/15·1/15；推荐信 3 highly recommended，GRE not required；两 AOS：PDS 产品开发经理 / PDT 新产品开发工程师，录取时声明；2025 平均报告薪资 $116,000（自愿调查）；雇主 AesculaTech/Amca/Audria/Boeing/Boston Scientific/Delta/Lockheed Martin/Medtronic/Northrop Grumman 等；排除 DEN 在线版与 PhD。",
 "USC MS Biostatistics（usc-bio-ms）：已核验入库。Keck 医学院 Population and Public Health Sciences 系，39 学分、典型 2 年、硕士论文 4 学分（PM 594a/b）；官网未标注 STEM，stem:0；Fall Priority 12/1·Final 4/1，Spring 10/1·3/1，Summer 10/1·3/1；GPA ≥3.0、3 推荐信（至少 1 学术，≤1 年系信纸签名）、CV/resume、PS，GRE not required，经 SOPHAS 申请；先修定量领域本科 + 微积分/线代/统计导论/编程；核心 PM 510L/511aL/511bL/512/513/518a + 统计理论 PM 522a/b 或 618；语言最低分/学费/申请费金额/薪资未公布留空；排除 Progressive Degree 本校贯通与 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：MS Environmental Data Science（details/usc-c97fb24.html）、MS Mathematical Data Science（details/usc-ce4fd5a.html，Dornsife 口径 stem:0）、MS Engineering Management（details/usc-c32a6e0.html）、MS Product Development Engineering（details/usc-cc9187d.html）、MS Biostatistics（details/usc-c568b0a.html，Keck 口径 stem:0）。重探：Stanford/USC/Rice 系站仍 200；JHU Eng 403、NYU GSAS 202 0B 空壳仍不可取正文；UT Stat/Math 仍 3.9KB 小字节 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"]))
