# -*- 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-mgtsc-ms"; PAGE="details/stanford-mgtsc-ms.html"
if ('"'+PID+'"') in r:
    print(PID,"已存在，跳过"); sys.exit(0)

dur=("授课型；至少 45 units，课程编号 100 级及以上；bulletin 未设硬性论文要求；"
     "Breadth 广度 4 门，四领域各一门且 letter grade：Optimization and Algorithms / Data Science, Probability, and Stochastics / Strategy, Entrepreneurship, and Organizations / Modeling, Decision, and Management Science Applications；"
     "Depth 深度 3 门 MS&E 研究生课且 letter grade，四方向选一或自设：Data, AI, and Decisions / Financial Analytics / Technology and Engineering Management / Technology Policy；其余为研究生选修补足学分")
rank="bulletin 未单列硬性先修课程清单；项目立足运筹、概率统计、优化、计算机科学与工程交叉，录取背景以工程、数学、运筹、计算机及相关定量科学为主（录取分布，非最低门槛）"

entry=(
 '{id:"'+PID+'",s:"stanford",n:"管理科学与工程硕士（MS）",'
 'en:"MS in Management Science and Engineering, Department of Management Science and Engineering (MS&E)",'
 'dept:"管理科学与工程系（MS&E，跨运筹/定量方法/工程/商业分析）",college:"Stanford University · School of Engineering",disc:"eng",lvl:"m",deg:"MS",'
 'dur:"'+dur+'",stem:0,rank:"'+rank+'",'
 ' test:{cls:""},ddl:"",lang:"",tui:"",'
 ' url:"'+PAGE+'"},'
)

anchor='url:"details/stanford-cme-ms.html"},];'
assert anchor in r, "PROGRAMS 锚点未找到"
r=r.replace(anchor, 'url:"details/stanford-cme-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)
