# -*- coding: utf-8 -*-
import io,sys,os
sys.stdout=io.TextIOWrapper(sys.stdout.buffer,encoding="utf-8")
b=r"D:\work buddy\2026-11-05-14-15-52"
f=os.path.join(b,"index_main.html")
r=open(f,encoding="utf-8").read()

PID="stanford-cme-ms"; PAGE="details/stanford-cme-ms.html"
if ('"'+PID+'"') in r:
    print(PID,"已存在，跳过"); sys.exit(0)

dur=("共 45 units 在校课程，无论文要求（可参与研究项目）；课程编号 200 级及以上，至少 36 units letter-graded，letter 课 C- 及以上、累计 GPA ≥3.0(B)；"
     "四方向：General CME / Data Science / Imaging Science / Mathematical and Computational Finance；"
     "Requirement 1 Foundational 基础 12 units（六核心选四，letter grade）；Requirement 2 Computing and Programming 计算编程 6 units（letter grade，CME 方向推荐 CME213）；"
     "Requirement 3 Breadth Electives 广度选修 15 units；Depth in Discipline 专项深度由系里首季末前审批")
rank="bulletin 未设硬性专业背景要求；推荐预备课程为高年级本科线代、概率、微分方程、随机过程、数值方法并具备编程能力（先修背景要求，非录取最低门槛；录取分布，非最低门槛）"

entry=(
 '{id:"'+PID+'",s:"stanford",n:"计算与数学工程硕士（MS）",'
 'en:"MS in Computational and Mathematical Engineering, Institute for Computational and Mathematical Engineering (ICME)",'
 'dept:"计算与数学工程研究所（ICME，跨数学/计算/工程/应用科学）",college:"Stanford University · 工程学院（ICME 跨学科研究所）",disc:"eng",lvl:"m",deg:"MS",'
 'dur:"'+dur+'",stem:0,rank:"'+rank+'",'
 ' test:{cls:""},ddl:"",lang:"",tui:"",'
 ' url:"'+PAGE+'"},'
)

anchor='url:"details/stanford-bioe-ms.html"},];'
assert anchor in r, "PROGRAMS 锚点未找到"
r=r.replace(anchor, 'url:"details/stanford-bioe-ms.html"},\n'+entry+'];', 1)

vd_marker='const VERIFIED_DETAILS=new Set(["'
assert vd_marker in r
vd_part=r.split("VERIFIED_DETAILS",1)[1].split("]",1)[0]
if ('"'+PAGE+'"') not in vd_part:
    r=r.replace(vd_marker, 'const VERIFIED_DETAILS=new Set(["'+PAGE+'","', 1)

assert '"'+PAGE+'"' in r, PAGE+" 未在主文件中出现"
open(f,"w",encoding="utf-8",newline="").write(r)
print("入库完成：PROGRAMS +1；VD 已登记；CATD det 已指向核验页")
print("  +", PID, PAGE)
