# -*- coding: utf-8 -*-
import io, sys, os, ssl, urllib.request, urllib.error, 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")
ctx=ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE

# 卡点重探
checks=[
 ("stanford_grad","https://gradadmissions.stanford.edu/"),
 ("usc_viterbi","https://viterbigradadmission.usc.edu/"),
 ("jhu_eng","https://engineering.jhu.edu/"),
 ("nyu_gsas","https://gsas.nyu.edu/"),
 ("rice_cs","https://cs.rice.edu/"),
 ("cornell_chem_ms","https://chemistry.cornell.edu/graduate-program/ms-program"),
]
for name,url in checks:
    try:
        req=urllib.request.Request(url,headers={"User-Agent":"Mozilla/5.0"})
        r=urllib.request.urlopen(req,timeout=12,context=ctx)
        print(name,r.status,len(r.read()))
    except urllib.error.HTTPError as e:
        print(name,"HTTP",e.code)
    except Exception as e:
        print(name,"ERR",type(e).__name__)

# 刷新基线
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["programs"]=len(lvl); b["programs_master"]=lvl.count("m"); b["programs_phd"]=lvl.count("d")
b["vd_set"]=len(set(vd)); b["details_html"]=details; b["node_check"]="exit 0"
b["pending_browser_check"].append("details/nyu-c568b0a.html 浏览器实开待后端会话恢复后补核（六卡静态核对已通过）")
b["blocked_notes"].append("第四十三轮：NYU Biostatistics MS 入库（覆盖 CATD 占位 det）；JHU AAP 4 条（Applied Economics/Financial Economics/Bioinformatics/GIS）e-catalogue 可达但继续教育/在职倾向，暂记待终检不入库；Cornell chemistry 403；Cornell BEE 导航聚合页信息不足；UT Psychology PhD-only 留批次5。")
b["note"]="第四十三轮：NYU Biostatistics MS 入库（+1）。批次4 升级 / 批次5 博士补齐与终检未完成。"
json.dump(b,open("_heartbeat_baseline.json","w",encoding="utf-8"),ensure_ascii=False,indent=2)
print("\n基线:",b["programs"],"master",b["programs_master"],"phd",b["programs_phd"],"vd",b["vd_set"],"details",b["details_html"],"mtime",mt)
