# -*- coding: utf-8 -*-
import io, sys, os
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()

# 1. PROGRAMS 追加（末条 rice-mbe 无逗号锚点）
new_progs = [
    '{id:"unc-cbph-ms",s:"unc",n:"细胞生物学与生理学硕士（生物医学研究）",en:"Master of Science in Cell Biology and Physiology, Biomedical Research",dept:"Department of Cell Biology and Physiology",college:"School of Medicine",disc:"sci",lvl:"m",deg:"MS",dur:"2学期",stem:1,test:{cls:""},ddl:"",lang:"",tui:"",url:"details/unc-cbph-ms.html"}',
    '{id:"unc-enec-ms",s:"unc",n:"环境生态硕士",en:"Master of Science in Environment and Ecology",dept:"Environment, Ecology and Energy (E3P) Interdisciplinary Program",college:"College of Arts and Sciences",disc:"sci",lvl:"m",deg:"MS",dur:"2年",stem:1,test:{cls:""},ddl:"",lang:"",tui:"",url:"details/unc-enec-ms.html"}',
    '{id:"unc-hbeh-mph",s:"unc",n:"健康行为公共卫生硕士",en:"Master of Public Health in Health Behavior",dept:"Department of Health Behavior",college:"Gillings School of Global Public Health",disc:"med",lvl:"m",deg:"MPH",dur:"2年",stem:0,test:{cls:""},ddl:"",lang:"",tui:"",url:"details/unc-hbeh-mph.html"}',
    '{id:"unc-mhch-mph",s:"unc",n:"妇幼健康公共卫生硕士",en:"Master of Public Health in Maternal, Child and Family Health",dept:"Department of Maternal and Child Health",college:"Gillings School of Global Public Health",disc:"med",lvl:"m",deg:"MPH",dur:"2年",stem:0,test:{cls:""},ddl:"",lang:"",tui:"",url:"details/unc-mhch-mph.html"}',
    '{id:"unc-nutrition-mph",s:"unc",n:"营养学公共卫生硕士-营养师方向",en:"Master of Public Health in Nutrition, Nutrition and Dietetics",dept:"Department of Nutrition",college:"Gillings School of Global Public Health",disc:"med",lvl:"m",deg:"MPH",dur:"2年",stem:0,test:{cls:""},ddl:"",lang:"",tui:"",url:"details/unc-nutrition-mph.html"}',
]
prog_anchor = 'url:"details/rice-mbe.html"}\n];'
prog_replacement = 'url:"details/rice-mbe.html"},\n' + ',\n'.join(new_progs) + '\n];'
assert prog_anchor in idx, "PROGRAMS anchor not found"
idx = idx.replace(prog_anchor, prog_replacement, 1)

# 2. CATD 追加（末条 rice-mbe 无逗号锚点）
new_catd = [
    '["unc","Department of Cell Biology and Physiology, School of Medicine","Master of Science in Cell Biology and Physiology, Biomedical Research","细胞生物学与生理学硕士（生物医学研究）","MS","https://catalog.unc.edu/graduate/schools-departments/cell-biology-physiology/","sci","details/unc-cbph-ms.html"]',
    '["unc","Environment, Ecology and Energy (E3P) Interdisciplinary Program","Master of Science in Environment and Ecology","环境生态硕士（MS）","MS","https://catalog.unc.edu/graduate/schools-departments/environment-ecology/","sci","details/unc-enec-ms.html"]',
    '["unc","Department of Health Behavior, Gillings School of Global Public Health","Master of Public Health in Health Behavior","健康行为公共卫生硕士（MPH）","MPH","https://catalog.unc.edu/graduate/schools-departments/health-behavior/","med","details/unc-hbeh-mph.html"]',
    '["unc","Department of Maternal and Child Health, Gillings School of Global Public Health","Master of Public Health in Maternal, Child and Family Health","妇幼健康公共卫生硕士（MPH）","MPH","https://catalog.unc.edu/graduate/schools-departments/maternal-child-health/","med","details/unc-mhch-mph.html"]',
    '["unc","Department of Nutrition, Gillings School of Global Public Health","Master of Public Health in Nutrition, Nutrition and Dietetics","营养学公共卫生硕士-营养师方向（MPH）","MPH","https://catalog.unc.edu/graduate/schools-departments/nutrition/","med","details/unc-nutrition-mph.html"]',
]
catd_anchor = 'details/rice-mbe.html"]\n];'
catd_replacement = 'details/rice-mbe.html"],\n' + ',\n'.join(new_catd) + '\n];'
assert catd_anchor in idx, "CATD anchor not found"
idx = idx.replace(catd_anchor, catd_replacement, 1)

# 3. VD 追加（在最后一个 det 后、"]);" 前插入）
vd_new = ', "details/unc-cbph-ms.html", "details/unc-enec-ms.html", "details/unc-hbeh-mph.html", "details/unc-mhch-mph.html", "details/unc-nutrition-mph.html"'
vd_anchor = '"details/rice-mbe.html"]);'
vd_replacement = '"details/rice-mbe.html"' + vd_new + ']);'
assert vd_anchor in idx, "VD anchor not found"
idx = idx.replace(vd_anchor, vd_replacement, 1)

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