# -*- 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()

RICE_LANG="TOEFL iBT 90 / IELTS 7 / Duolingo 115（最低，EPMP 工程硕士通用）；英语授课学位可豁免"
RICE_BG="工程或相关学科学士；GPA 3.0+；全部成绩单、3 推荐信；GRE 代码 6609；holistic 评审"
RICE_TUI="项目级费率未单列，留空不估算；merit 奖学金按项目口径自动评审"
entries=[
 dict(id="rice-mche-ms",s="rice",n="化学与生物分子工程硕士",en="Master of Chemical Engineering (MChE)",dept="Chemical and Biomolecular Engineering",college="George R. Brown School of Engineering and Computing",disc="eng",deg="MChE",dur="professional course-based non-thesis；学分总数待 GA/系站补核",stem=0,test="opt",ddl="Fall 2026-12-31（Late 2027-04-01）；Spring 2026-10-01",lang=RICE_LANG,tui=RICE_TUI,url="details/rice-chemical-biomolecular-engineering.html"),
 dict(id="rice-mcee-ms",s="rice",n="土木与环境工程硕士",en="Master of Civil and Environmental Engineering (MCEE)",dept="Civil and Environmental Engineering",college="George R. Brown School of Engineering and Computing",disc="eng",deg="MCEE",dur="30 学分 500 级及以上，含 2 学分 final project；non-thesis",stem=0,test="opt",ddl="Fall 2027-01-15；Spring 2026-11-01",lang=RICE_LANG,tui=RICE_TUI,url="details/rice-civil-environmental-engineering.html"),
 dict(id="rice-mmsne-ms",s="rice",n="材料科学与纳米工程硕士",en="Master of Materials Science and NanoEngineering (MMSNE)",dept="Materials Science and NanoEngineering",college="George R. Brown School of Engineering and Computing",disc="eng",deg="MMSNE",dur="non-thesis professional；学分总数待 GA/系站补核",stem=0,test="opt",ddl="Fall 2027-02-01；Spring 2026-11-15",lang=RICE_LANG,tui=RICE_TUI,url="details/rice-materials-science-nanoengineering.html"),
 dict(id="rice-mbe-ms",s="rice",n="生物工程硕士",en="Master of Bioengineering (MBE)",dept="Bioengineering",college="George R. Brown School of Engineering and Computing",disc="eng",deg="MBE",dur="non-thesis；full-time/part-time；学分总数待 GA 补核",stem=0,test="opt",ddl="Applied Bioengineering Fall 2027-02-01(Priority)/04-15(Final)，Spring 2026-10-15；GMI Fall 2027-01-31，无春季",lang=RICE_LANG,tui=RICE_TUI,url="details/rice-bioengineering.html"),
 dict(id="dartmouth-hds-ms",s="dartmouth",n="健康数据科学硕士（在校版）",en="MS in Health Data Science (On-Campus)",dept="Geisel 医学院 / The Dartmouth Institute",college="Geisel School of Medicine",disc="med",deg="MS",dur="在校 12 个月；每班约 30-40 人；10 周 capstone",stem=0,test="opt",ddl="SOPHAS 三轮：R1 2026-12-01 / R2 2027-02-01 / R3 2027-04-15",lang="非母语须 TOEFL/IELTS/Duolingo 之一（成绩 2 年内）；满足学位豁免条件可豁免",tui="学费 $66,190（12 个月在校）；merit 奖学金",url="details/dartmouth-health-data-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:"rice-mme-ms",s:"rice"'
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))
