# -*- 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-ds-ms",s="vanderbilt",n="数据科学硕士",en="Master of Science in Data Science (MS DS)",dept="Data Science Institute",college="Data Science Institute",disc="cs",deg="MS",dur="30 学分；9 个月 4 模块全日制",stem=0,test="opt",ddl="仅秋季；R1 2026-01-15、R2 2/15、R3 3/15、R4 4/15、R5 5/15",lang="TOEFL 100(小分≥21)；IELTS 7.0(小分≥6.5)；Duolingo 130；英语学位可豁免",tui="2025-26 学费 $72,570 + 保险 $4,314 + 杂费；奖学金 25%-100% 学费",url="details/vanderbilt-www-datascience-msprogram.html"),
 dict(id="geo-dsan-ms",s="geo",n="数据科学与分析硕士",en="Master of Science in Data Science & Analytics (MS DSAN)",dept="College of Arts & Sciences",college="College of Arts & Sciences",disc="cs",deg="MS",dur="30 学分；全日制最快 16 个月",stem=1,test="notreq",ddl="Priority 2027-01-15；Final 2027-02-15",lang="IELTS ≥7.5；TOEFL iBT ≥100；不接受 MyBest",tui="2026-27 每学分 $2,758；30 学分总学费 $82,740；全日制 $24,822/学期",url="details/geo-data-science-analytics-ms.html"),
 dict(id="geo-hids-ms",s="geo",n="健康信息学与数据科学硕士",en="Master of Science in Health Informatics & Data Science (HIDS)",dept="Biomedical Graduate Education",college="School of Medicine",disc="cs",deg="MS",dur="12 个月；30 学分",stem=1,test="opt",ddl="Early 2027-01-15；Priority 5/15；Final 7/1",lang="项目级最低分待补（研究生院口径）",tui="BGE 通用 2026-27：≥12cr/学期 $31,416；不足 12cr $2,618/学分",url="details/geo-health-informatics-data-science-ms.html"),
 dict(id="geo-biostat-ms",s="geo",n="生物统计学硕士",en="Master of Science in Biostatistics",dept="Dept. of Biostatistics, Bioinformatics & Biomathematics",college="School of Medicine",disc="cs",deg="MS",dur="17 个月；30 核心 + 2 Practicum = 32 学分",stem=0,test="notreq",ddl="Early 2027-01-15；Priority 5/15；Final 7/1",lang="TOEFL/IELTS 如适用；项目级最低分待补",tui="BGE 通用 2026-27：≥12cr/学期 $31,416；不足 12cr $2,618/学分；部分 GRA",url="details/geo-biostatistics-ms.html"),
 dict(id="geo-dspp-ms",s="geo",n="公共政策数据科学硕士",en="Master of Science in Data Science for Public Policy (MS-DSPP)",dept="McCourt School of Public Policy",college="McCourt School of Public Policy",disc="cs",deg="MS",dur="2 年；33 核心 + 6 选修 = 39 学分",stem=1,test="opt",ddl="Early 2026-12-01；Priority 2027-01-15；Final 3/1",lang="TOEFL iBT 100(新制 5)；IELTS Academic 7.0",tui="每学分 $2,758；39 学分打包总额官网未单列",url="details/geo-data-science-for-public-policy-ms.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-biostat-ms",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))
