# -*- 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"]=2680; 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/ut-c863142.html 浏览器实开待后端会话恢复后补核（CS MSc 六卡覆盖升级，静态核对已通过）",
 "details/ut-c4f263b.html 浏览器实开待后端会话恢复后补核（MScAC 六卡覆盖升级，静态核对已通过）",
 "details/ut-c6baa60.html 浏览器实开待后端会话恢复后补核（Public Health 六卡覆盖升级，静态核对已通过）",
 "details/ut-kine-msc.html 浏览器实开待后端会话恢复后补核（新建六卡，静态核对已通过）",
 "details/ut-nutr-msc.html 浏览器实开待后端会话恢复后补核（新建六卡，静态核对已通过）",
]
base={os.path.basename(x.split()[0]):x for x in b.get("pending_browser_check",[])}
for p in new_pending: base[os.path.basename(p.split()[0])]=p
b["pending_browser_check"]=list(base.values())
bn=b.get("blocked_notes",[])
bn.append("第四十二轮：Stanford/USC/JHU 持续 403；NYU GSAS 202 0B；Cornell Chem MS 404；Rice CS 200。ut-cs-msc 旧条目已存在，误追加重复后删除；UT MScAC/Public Health/Kinesiology/Nutritional Sciences 新增 4 条。")
b["blocked_notes"]=list(dict.fromkeys(bn))
b["note"]="第四十二轮：4 条 UT SGS 硕士新增（MScAC / Public Health MPH·MSc / Kinesiology MSc / Nutritional Sciences MSc）+ 1 条 CS MSc 六卡覆盖升级（旧条目已在库）。批次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"],"catd",b["catd"],"vd",b["vd_set"],"details",b["details_html"],"pending",len(b["pending_browser_check"]),"blocked",len(b["blocked_notes"]),"mtime",mt)
