# -*- 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="geo-cs-ms",s="geo",n="计算机科学硕士",en="Master of Science in Computer Science (MS CS)",dept="Department of Computer Science",college="Georgetown College",disc="cs",deg="MS",dur="10 门课 coursework，或 8 门课 + 论文",stem=0,test="opt",ddl="Spring 2026-10-01；Fall Priority 2027-01-15，Final 2027-04-01",lang="TOEFL iBT 90（新制 4.5）；IELTS 7.0；学位豁免见研究生院口径",tui="学费/资助待补",url="details/geo-computer-science-ms.html"),
 dict(id="jhu-finance-ms",s="jhu",n="金融硕士",en="Master of Science in Finance (MS Finance)",dept="Carey Business School",college="Carey Business School",disc="biz",deg="MS",dur="30 学分；全日制 2 学期（秋春）",stem=1,test="",ddl="Carey 站 403 不可达，截止待补",lang="Carey 站不可达，语言门槛待补",tui="学费/资助待补",url="details/jhu-c20f33f.html"),
 dict(id="jhu-baai-ms",s="jhu",n="商业分析与人工智能硕士",en="MS in Business Analytics and Artificial Intelligence (MS BA-AI)",dept="Carey Business School",college="Carey Business School",disc="biz",deg="MS",dur="36 学分；全日制 3 学期（春夏秋）",stem=1,test="",ddl="Carey 站 403 不可达，截止待补",lang="Carey 站不可达，语言门槛待补",tui="学费/资助待补",url="details/jhu-c704c8a.html"),
 dict(id="geo-bioinfo-ms",s="geo",n="生物信息学硕士",en="Master of Science in Bioinformatics",dept="Biomedical Graduate Education",college="School of Medicine",disc="cs",deg="MS",dur="2-3 学期；full-time/accelerated",stem=0,test="",ddl="Spring 2026-11-01；Fall Early 2027-01-15，Priority 2027-05-15",lang="项目页未列，语言门槛待补",tui="merit/service 奖学金；金额待补",url="details/geo-bioinformatics-ms.html"),
 dict(id="vandy-biostat-ms",s="vanderbilt",n="生物统计学硕士",en="Master of Science in Biostatistics",dept="Department of Biostatistics",college="Graduate School",disc="cs",deg="MS",dur="核心 31 + 选修 9 = 40 学分",stem=0,test="",ddl="项目页未列，截止待补",lang="项目页未列，语言门槛待补",tui="学费/资助待补",url="details/vanderbilt-www-biostatistics-graduate-master-of-science.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:"illinois-mspe-ms",s:"illinois"'
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))
