# -*- coding: utf-8 -*-
import io, sys, os, json, re, datetime
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
os.chdir(r"D:\work buddy\2026-11-05-14-15-52")
b=json.load(open("_heartbeat_baseline.json",encoding="utf-8"))
idx=open("index_main.html",encoding="utf-8").read()
seg=idx[idx.find("const PROGRAMS="):idx.find("const CATD=")]
lvl=re.findall(r'lvl:"([^"]+)"',seg)
vd=re.findall(r'"([^"]+\.html)"',idx[idx.find("const VERIFIED_DETAILS="):])
details=len([f for f in os.listdir("details") if f.endswith(".html")])
mt=datetime.datetime.fromtimestamp(os.path.getmtime("index_main.html")).strftime("%Y-%m-%d %H:%M:%S")

b["updated_at"]=mt; b["index_main_mtime"]=mt
b["schools"]=36
b["programs"]=len(lvl); b["programs_master"]=lvl.count("m"); b["programs_phd"]=lvl.count("d")
b["catd"]=2676; b["dead_links"]=0; b["excluded_residue"]=0
b["vd_set"]=len(set(vd)); b["details_html"]=details; b["node_check"]="exit 0"

new_pending=[
 "details/uw-c435976.html 浏览器实开待后端会话恢复后补核（六卡静态核对已通过）",
 "details/uw-cb1d654.html 浏览器实开待后端会话恢复后补核（六卡静态核对已通过）",
 "details/uw-cb1705c.html 浏览器实开待后端会话恢复后补核（六卡静态核对已通过）",
 "details/dartmouth-engineering-sciences-ms.html 浏览器实开待后端会话恢复后补核（六卡静态核对已通过）",
 "details/yale-personalized-medicine-applied-engineering.html 浏览器实开待后端会话恢复后补核（六卡静态核对已通过）",
]
base_pending={os.path.basename(x.split()[0]):x for x in b.get("pending_browser_check",[])}
for p in new_pending:
    base_pending[os.path.basename(p.split()[0])]=p
b["pending_browser_check"]=list(base_pending.values())

bn=b.get("blocked_notes",[])
bn.append("UT Statistics MSc / UT Mathematics MSc：系站仍返回 ~3.9KB 小字节拦截页（非项目正文），Cloudflare 类 challenge，仍不可读，保留卡点 #101，不凑数入库。")
bn.append("JHU engineering.jhu.edu / bme.jhu.edu 403；NYU gsas.nyu.edu URLError/202 0B 空壳；Rice stat.rice.edu / jonesbusiness.rice.edu DNS 不通；UVA grad 站 202 0B；Emory CS SSL 错误；Duke Medical Physics 读取超时；CMU Learning Engineering 412B 重定向；Dartmouth Medical Informatics URLError；Vandy Medical Physics 旧路径 404。")
bn.append("【持续可达】Stanford cs.stanford.edu / gradadmissions.stanford.edu 200 真实正文；USC Viterbi 200 208935B、Rice CS 200 60422B 可达。Stanford todo 剩余条目全为 PhD（批次5），留待批次5核验。")
bn.append("本轮已探活留待下轮：Notre 工程小字节页四条（MSAE Aerospace 15997B / MEng CEE 17490B / MSCE Civil 16965B / MSIM Interdisciplinary Math 16422B）待读正文定性；JHU EHE MS e-catalogue 313287B 可达待核。")
b["blocked_notes"]=list(dict.fromkeys(bn))

b["note"]="第三十一轮：5 条硕士核验入库（UW MEng 机械与机电 Co-op；UW MEng 化工 Co-op；UW MMath 计算数学 Co-op；Dartmouth Engineering Sciences MS；Yale PMAE MS）。UW 三条为 Co-op 独立通道，与库内非 Co-op 条目区分；catalog/项目页未公布的截止/语言/标化/打包学费留空待补，不臆造；STEM 仅官网明示才标 1，加拿大项目 stem:0。批次4 升级 / 批次5 博士补齐与终检未完成。"
json.dump(b,open("_heartbeat_baseline.json","w",encoding="utf-8"),ensure_ascii=False,indent=2)
print("programs",b["programs"],"master",b["programs_master"],"phd",b["programs_phd"],"vd",b["vd_set"],"details",b["details_html"],"pending",len(b["pending_browser_check"]),"blocked",len(b["blocked_notes"]),"eq",len(b.get("excluded_qual",[])),"mtime",mt)
