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

entries=[
 dict(id="vandy-mscs",s="vanderbilt",n="计算机科学硕士（在校）",en="MS in Computer Science",dept="College of Connected Computing",college="College of Connected Computing",disc="cs",deg="MS",dur="30 学分；1.5–2 年",stem=0,test="notreq",ddl="Spring 2027 10/15；Fall 2027 priority 1/15、regular 3/1",lang="TOEFL iBT 约 90（单项≥4.0）/IELTS 7.0（单项≥6.0）/DET 130；境外学位需 WES/NACES 认证",tui="MS 自费；专属打包学费未单列，待补；Merit 奖学金随录取自动评审",url="details/vanderbilt-engineering-departments-computer-science-graduate.html"),
 dict(id="vandy-mscee",s="vanderbilt",n="土木与环境工程硕士",en="MS in Civil and Environmental Engineering",dept="Department of Civil and Environmental Engineering",college="School of Engineering",disc="eng",deg="MS",dur="Thesis / Non-thesis 两选项",stem=0,test="notreq",ddl="MS priority 2027-01-08、final 2027-03-15",lang="TOEFL 89 / IELTS 7.0 / DET 130；英语国家学位可豁免",tui="MS 自费；专属打包学费未单列，待补",url="details/vanderbilt-engineering-departments-civil-environmental-engineering.html"),
 dict(id="vandy-msmse",s="vanderbilt",n="材料科学与工程硕士（跨学科）",en="MS in Interdisciplinary Materials Science (IMS)",dept="Interdisciplinary Materials Science Program",college="School of Engineering",disc="eng",deg="MS",dur="24 课程学分 + thesis + ≥6 研究学分",stem=0,test="notreq",ddl="MS 总站口径 priority 1/8、final 3/15；系站仅列 PhD 截止",lang="TOEFL 89 / IELTS 7.0 / DET 130；符合豁免可申请豁免",tui="MS 自费；专属打包学费未单列，待补",url="details/vanderbilt-engineering-materials-science.html"),
 dict(id="jhu-ams-mse",s="jhu",n="应用数学与统计工程硕士",en="M.S.E. in Applied Mathematics and Statistics",dept="Department of Applied Mathematics and Statistics",college="Whiting School of Engineering",disc="cs",deg="MSE",dur="至少两学期全日制；8 门研究生课",stem=0,test="",ddl="待补（catalogue 未列）",lang="待补（catalogue 未列）",tui="打包学费待补；资助名额待补",url="details/jhu-c467c7b.html"),
 dict(id="jhu-bme-mse",s="jhu",n="生物医学工程工程硕士",en="M.S.E. in Biomedical Engineering",dept="Department of Biomedical Engineering",college="Whiting School of Engineering",disc="eng",deg="MSE",dur="course-based 30cr / thesis 30cr+thesis 第二年",stem=0,test="",ddl="通常 1 月上旬（每年更新）；具体日期待补",lang="待补（catalogue 未列）",tui="无系内资助；外部资助可申；打包学费待补",url="details/jhu-c77beb0.html"),
]

def entry_str(e):
    stem="1" if e["stem"] else "0"
    return ('{id:"'+e["id"]+'",s:"'+e["s"]+'",n:"'+e["n"]+'",en:"'+e["en"]+'",dept:"'+e["dept"]+'",college:"'+e["college"]+'",'
            'disc:"'+e["disc"]+'",lvl:"m",deg:"'+e["deg"]+'",dur:"'+e["dur"]+'",stem:'+stem+',rank:"",'
            'test:{cls:"'+e["test"]+'"},ddl:"'+e["ddl"]+'",lang:"'+e["lang"]+'",tui:"'+e["tui"]+'",url:"'+e["url"]+'"},')

prog_seg_start=idx.find("const PROGRAMS=")
prog_seg_end=idx.find("const CATD=")
prog_seg=idx[prog_seg_start:prog_seg_end]
anchor='{id:"vandy-mengesi",s:"vanderbilt"'
anchor_pos=idx.find(anchor)
assert anchor_pos>0,"末条锚点未找到"
line_end=idx.find("\n",anchor_pos)
to_add=[e for e in entries if ('{id:"'+e["id"]+'"') not in prog_seg]
if to_add:
    block="\n"+"\n".join(entry_str(e) for e in to_add)
    idx=idx[:line_end]+block+idx[line_end:]
    print("PROGRAMS 追加",len(to_add),"条：",[e["id"] for e in to_add])
else:
    print("PROGRAMS 无新增（均已存在）")

vd_m=re.search(r'(const VERIFIED_DETAILS=new Set\(\[)(.*?)(\]\);)',idx,re.S)
assert vd_m,"VD 段未找到"
vd_body=vd_m.group(2)
vd_list=re.findall(r'"([^"]+)"',vd_body)
new_det=[e["url"] for e in entries if e["url"] not in vd_list]
if new_det:
    add_str=",".join('"'+d+'"' for d in new_det)
    new_vd_body=vd_body.rstrip()
    if not new_vd_body.endswith(","):
        new_vd_body=new_vd_body+","
    new_vd_body=new_vd_body+add_str
    idx=idx[:vd_m.start(2)]+new_vd_body+idx[vd_m.end(2):]
    print("VD 登记",len(new_det),"条：",new_det)
else:
    print("VD 无新增")

open(IDX,"w",encoding="utf-8").write(idx)
print("写回完成，字符",len(idx))
