# -*- 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-applied-econ-ma",s="geo",n="应用经济学文学硕士",en="Master of Arts in Applied Economics (MA Applied Economics)",dept="Department of Economics",college="College of Arts & Sciences",disc="soc",deg="MA",dur="30 学分；全日制 1 年 / part-time 2 年",stem=0,test="req",ddl="Priority 2027-01-15；Final 2027-04-01",lang="TOEFL 100(新制 5)；IELTS 7.0；英语学位可豁免",tui="专属打包学费未单列；MA AE 享 20% 学费 merit 折扣",url="details/geo-applied-economics-ms.html"),
 dict(id="geo-fin-econ-ms",s="geo",n="金融经济学硕士",en="Master of Science in Financial Economics (MS-FECO)",dept="Department of Economics",college="College of Arts & Sciences",disc="soc",deg="MS",dur="45 学分；2 年",stem=1,test="req",ddl="Priority 2027-01-15；Final 2027-04-01",lang="TOEFL 100(新制 5)；IELTS 7.0；英语学位可豁免",tui="专属打包学费未单列；MS-FECO 享 1/3 学费 merit 折扣",url="details/geo-financial-economics-ms.html"),
 dict(id="geo-bmb-ms",s="geo",n="生物化学与分子生物学硕士",en="MS in Biochemistry & Molecular Biology",dept="Biomedical Graduate Education",college="School of Medicine",disc="sci",deg="MS",dur="30 学分；10+ 个月",stem=0,test="opt",ddl="Spring 11/1；Fall Early 1/15 Priority 5/15 Final 7/1",lang="项目级最低分待补（研究生院 FAQ 口径）",tui="BGE 通用 2026-27：≥12cr/学期 $31,416；不足 12cr $2,618/学分；自动纳入 merit 奖学金评审",url="details/geo-biochemistry-molecular-biology-ms.html"),
 dict(id="geo-esm-ms",s="geo",n="环境与可持续管理硕士",en="MS in Environment and Sustainability Management (MS-ESM)",dept="Earth Commons Institute × McDonough School of Business",college="McDonough School of Business",disc="biz",deg="MS",dur="30 学分；10 个月",stem=1,test="opt",ddl="R1 10/9、R2 11/6、R3 1/8、R4 2/19、R5 3/12；rolling 6/25",lang="TOEFL 100(新制 5)；IELTS Academic 7.5",tui="2026-27 学费 $79,950($2,665/学分)+保险 $4,350；79% 获奖平均 $11,265",url="details/geo-environment-sustainability-management-ms.html"),
 dict(id="vandy-maecon-ma",s="vanderbilt",n="经济学文学硕士（GPED）",en="MA in Economics — Graduate Program in Economic Development (GPED)",dept="Department of Economics",college="College of Arts & Science",disc="soc",deg="MA",dur="30 学分；21 个月（部分 15 个月）",stem=1,test="opt",ddl="Fall 2027-02-15；无申请费",lang="TOEFL iBT 88；IELTS 7.0；英语学位可豁免",tui="专属学费未单列；MA 仅系内小奖+校园岗位，资助主要保留 PhD",url="details/vanderbilt-as-economics-about-ma-economics.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:"geo-dspp-ms",s:"geo"'
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))
