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

p = "index_main.html"
idx = open(p, encoding="utf-8").read()

new_progs = [
    '{id:"rice-mme",s:"rice",n:"机械工程硕士",en:"Master of Mechanical Engineering",dept:"Department of Mechanical Engineering",college:"George R. Brown School of Engineering",disc:"eng",lvl:"m",deg:"MME",dur:"2年",stem:1,test:{cls:""},ddl:"",lang:"",tui:"",url:"details/rice-mme.html"}',
    '{id:"rice-mmsne",s:"rice",n:"材料科学与纳米工程硕士",en:"Master of Materials Science and NanoEngineering",dept:"Department of Materials Science and NanoEngineering",college:"George R. Brown School of Engineering",disc:"eng",lvl:"m",deg:"MMSNE",dur:"2年",stem:1,test:{cls:""},ddl:"",lang:"",tui:"",url:"details/rice-mmsne.html"}',
    '{id:"rice-mche",s:"rice",n:"化学工程硕士",en:"Master of Chemical Engineering",dept:"Department of Chemical and Biomolecular Engineering",college:"George R. Brown School of Engineering",disc:"eng",lvl:"m",deg:"MChE",dur:"2年",stem:1,test:{cls:""},ddl:"",lang:"",tui:"",url:"details/rice-mche.html"}',
    '{id:"rice-mstat",s:"rice",n:"统计硕士",en:"Master of Statistics",dept:"Department of Statistics",college:"George R. Brown School of Engineering",disc:"cs",lvl:"m",deg:"MStat",dur:"2年",stem:1,test:{cls:""},ddl:"",lang:"",tui:"",url:"details/rice-mstat.html"}',
    '{id:"rice-mbe",s:"rice",n:"生物工程硕士",en:"Master of Bioengineering",dept:"Department of Bioengineering",college:"George R. Brown School of Engineering",disc:"eng",lvl:"m",deg:"MBE",dur:"2年",stem:1,test:{cls:""},ddl:"",lang:"",tui:"",url:"details/rice-mbe.html"}',
]

new_catd = [
    '["rice","Department of Mechanical Engineering, George R. Brown School of Engineering","Master of Mechanical Engineering","机械工程硕士（MME）","MME","https://mech.rice.edu/academics/graduate-programs/masters-mechanical-engineering","eng","details/rice-mme.html"]',
    '["rice","Department of Materials Science and NanoEngineering, George R. Brown School of Engineering","Master of Materials Science and NanoEngineering","材料科学与纳米工程硕士（MMSNE）","MMSNE","https://msne.rice.edu/academics/graduate-programs/mmsne-program","eng","details/rice-mmsne.html"]',
    '["rice","Department of Chemical and Biomolecular Engineering, George R. Brown School of Engineering","Master of Chemical Engineering","化学工程硕士（MChE）","MChE","https://chbe.rice.edu/academics/graduate-programs/mche-program","eng","details/rice-mche.html"]',
    '["rice","Department of Statistics, George R. Brown School of Engineering","Master of Statistics","统计硕士（MStat）","MStat","https://statistics.rice.edu/master-statistics","cs","details/rice-mstat.html"]',
    '["rice","Department of Bioengineering, George R. Brown School of Engineering","Master of Bioengineering","生物工程硕士（MBE）","MBE","https://bioengineering.rice.edu/academics/masters-programs","eng","details/rice-mbe.html"]',
]

# PROGRAMS：末条 unc-polisci-tam-ma 后插入（末条无逗号）
prog_anchor = 'url:"details/unc-polisci-tam-ma.html"}\n];'
prog_new = ',\n'.join(new_progs)
prog_replacement = 'url:"details/unc-polisci-tam-ma.html"},\n' + prog_new + '\n];'
assert prog_anchor in idx, "PROGRAMS anchor not found"
idx = idx.replace(prog_anchor, prog_replacement, 1)

# CATD：末条 unc-polisci-tam-ma 后插入（末条无逗号）
catd_anchor = 'details/unc-polisci-tam-ma.html"]\n];'
catd_new = '\n' + ',\n'.join(new_catd)
catd_replacement = 'details/unc-polisci-tam-ma.html"],\n' + ',\n'.join(new_catd) + '\n];'
assert catd_anchor in idx, "CATD anchor not found"
idx = idx.replace(catd_anchor, catd_replacement, 1)

# VD：在 ]); 前插入
vd_start = idx.find("const VERIFIED_DETAILS=new Set(")
assert vd_start > 0
vd_end = idx.find("]);", vd_start)
assert vd_end > 0
new_dets = ', "details/rice-mme.html", "details/rice-mmsne.html", "details/rice-mche.html", "details/rice-mstat.html", "details/rice-mbe.html"'
idx = idx[:vd_end] + new_dets + idx[vd_end:]

open(p, "w", encoding="utf-8").write(idx)
print("APPENDED OK")
