# -*- 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-mcs-ms","details/rice-computer-science.html","On-Campus MCS"),
 ("rice-mds-ms","details/rice-data-science.html","On-Campus MDS"),
 ("rice-mece-ms","details/rice-electrical-computer-engineering.html","MECE"),
 ("cmu-mscf-ms","details/cmu-c8e8fa0.html","MSCF"),
 ("cmu-msm-ms","details/cmu-cdd17fa.html","MSM"),
]
for _,det,_ in new:
    tag=det+" 浏览器实开待后端会话恢复后补核（六卡静态核对已通过）"
    if det not in b["pending_browser_check"]:
        b["pending_browser_check"].append(tag)

notes=[
 "Rice On-Campus MCS（rice-mcs-ms）：已核验入库。CS 系，30 学分 non-thesis，通常 3 学期；5 方向 AI / Bioinformatics & CompBio / Data Science & ML / Management & Leadership / Systems & Security；COMP 608 必修；GPA 3.0+；成绩单/CV/SOP/3 推荐信/$85；GRE recommended not required；Spring 2027 Early 10/1 Final 11/1，Fall 2027 Early 2/10 本土 7/1 rolling；外部实习就业率 93%；语言/学费费率待补。排除 Online MCS、On-Campus MAI、On-Campus MDS、研究型 MS/PhD、第五年贯通。",
 "Rice On-Campus MDS（rice-mds-ms）：已核验入库。CS 系，31 学分 non-thesis，连续 3 学期，仅秋季入学；5 方向 AI / Business Analytics / Energy Transition & Sustainability / Image Processing（仅在校）/ Sports Analytics（仅在校）；COMP 543/549/557，末学期 D2K capstone；GPA 3.0+；3 推荐信/$85；GRE recommended not required；Fall Early 2/10 本土 7/1 rolling；语言/学费待补。排除 Online MDS、On-Campus MAI/MCS、研究型 MS/PhD。",
 "Rice MECE（rice-mece-ms）：已核验入库。ECE 系，30–32 学分（≥27 在 Rice），三学期全日制；7 方向 AI & Systems / Computer Engineering / Computer Vision / Digital Health / Neuroengineering / Quantum Engineering / Wireless Systems；ELEC 594 两学期 capstone；本科通常 EE/CE/CS/统计；GPA 3.0+；≥3 推荐信/$85；TOEFL 90/IELTS 7/Duolingo 115；GRE recommended not required；Fall Priority 12/15 Late 1/15；merit 奖学金覆盖 25%–66% 学费；学费费率待补。排除 PhD、研究型 MS（不直录）、MDH、第五年贯通。",
 "CMU MSCF（cmu-mscf-ms）：半核验入库。Tepper，匹兹堡+NYC 双城；第一学年核心+夏季实习+末学期选修；先修 Calculus I&II/Linear algebra/Calculus-based probability/≥1 学期 OOP；GRE/GMAT 或 MSCF 定量评估二选一（req）；3 推荐信/2 短文书+90 秒视频文书/邀请制面试/$125；R1 12/1 R2 3/1；班级 Fall 2026 平均 GPA 3.80、GRE Q169/V160（录取分布，非门槛）；毕业 6 个月内约 100% 就业，路径 Quant Research/S&T/Strats/Risk/PM/Data Science；语言最低分/学费费率待补；STEM 页面未明示，保守标 0。排除 MBA/MSBA/MSM/PhD。",
 "CMU MSM（cmu-msm-ms）：半核验入库。Tepper，STEM-designated，9 个月两学期四 Mini 全日制；任何本科专业+至少一门大学数学，不要求商业背景/工作经验；R1 10/14 R2 1/13 R3 3/3（国际生最后轮）R4P 5/5 R4F 6/16；Class 2026 37 人，平均工作经验 0.5 年、GPA 3.33（分布非门槛）、73% 国际生；Class 2025 平均接受薪资 $97,500（分布非门槛）；区域奖学金 $15k–30k；语言/GRE/学费待补。排除 MBA/MSBA/MSCF/PhD。",
 "卡点待复核（本轮新增）：CMU MSCS（c2ee442）主页与 prospective-students 页缺截止/语言/GRE/学费硬指标，需跟进 MSCS Handbook 或 SCS 总站；CMU MS Product Management（c46c856）实为 Online Education 的 AI Product Management Essentials 在线证书，非学位，按口径排除；CMU MS Learning Engineering（cafb6f5）412B 重定向页待跟进；Rice Statistics 系站 stat.rice.edu DNS 不通（11001）；Rice MFin catalog 仅目录条目无项目字段；CMU MSCB（c274a8e）语言/GRE/课程已抓全，留待下轮成页。",
]
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 On-Campus MCS（details/rice-computer-science.html）、Rice On-Campus MDS（details/rice-data-science.html）、Rice MECE（details/rice-electrical-computer-engineering.html）、CMU MSCF（details/cmu-c8e8fa0.html）、CMU MSM（details/cmu-cdd17fa.html）。重探：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"]))
