# -*- 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 追加（末条 unc-nutrition-mph 无逗号锚点）
new_progs = [
    '{id:"unc-mac",s:"unc",n:"会计硕士（在校）",en:"Master of Accounting, On-Campus",dept:"Kenan-Flagler Business School",college:"Kenan-Flagler Business School",disc:"biz",lvl:"m",deg:"MAC",dur:"1年",stem:1,test:{cls:""},ddl:"",lang:"",tui:"",url:"details/unc-mac.html"}',
    '{id:"unc-msm",s:"unc",n:"管理学理学硕士",en:"Master of Science in Management",dept:"Kenan-Flagler Business School",college:"Kenan-Flagler Business School",disc:"biz",lvl:"m",deg:"MSM",dur:"1年",stem:1,test:{cls:""},ddl:"",lang:"",tui:"",url:"details/unc-msm.html"}',
    '{id:"unc-meite",s:"unc",n:"教育创新技术与创业文学硕士",en:"MA in Educational Innovation, Technology, and Entrepreneurship",dept:"School of Education",college:"School of Education",disc:"edu",lvl:"m",deg:"MA",dur:"2年",stem:0,test:{cls:""},ddl:"",lang:"",tui:"",url:"details/unc-meite.html"}',
    '{id:"unc-ssw-msw",s:"unc",n:"社会工作硕士（2年在校）",en:"Master of Social Work, 2-Year Residential",dept:"School of Social Work",college:"School of Social Work",disc:"soc",lvl:"m",deg:"MSW",dur:"2年",stem:0,test:{cls:""},ddl:"",lang:"",tui:"",url:"details/unc-ssw-msw.html"}',
    '{id:"unc-nutrition-nfsh",s:"unc",n:"营养学公共卫生硕士-食物系统与健康方向",en:"MPH in Nutrition, Food Systems and Health, On-Campus",dept:"Department of Nutrition, Gillings School of Global Public 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-nutrition-nfsh.html"}',
]
prog_anchor = 'url:"details/unc-nutrition-mph.html"}\n];'
prog_replacement = 'url:"details/unc-nutrition-mph.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 追加（末条 unc-nutrition-mph 无逗号锚点）
new_catd = [
    '["unc","Kenan-Flagler Business School","Master of Accounting, On-Campus","会计硕士（在校，STEM-designated）","MAC","https://catalog.unc.edu/graduate/schools-departments/kenan-flagler-business-school/","biz","details/unc-mac.html"]',
    '["unc","Kenan-Flagler Business School","Master of Science in Management","管理学理学硕士（STEM-designated）","MSM","https://catalog.unc.edu/graduate/schools-departments/kenan-flagler-business-school/","biz","details/unc-msm.html"]',
    '["unc","School of Education","MA in Educational Innovation, Technology, and Entrepreneurship","教育创新技术与创业文学硕士（MEITE）","MA","https://catalog.unc.edu/graduate/schools-departments/education/","edu","details/unc-meite.html"]',
    '["unc","School of Social Work","Master of Social Work, 2-Year Residential","社会工作硕士（2年在校）","MSW","https://catalog.unc.edu/graduate/schools-departments/social-work/","soc","details/unc-ssw-msw.html"]',
    '["unc","Department of Nutrition, Gillings School of Global Public Health","MPH in Nutrition, Food Systems and Health, On-Campus","营养学公共卫生硕士-食物系统与健康方向（在校）","MPH","https://catalog.unc.edu/graduate/schools-departments/nutrition/","med","details/unc-nutrition-nfsh.html"]',
]
catd_anchor = 'details/unc-nutrition-mph.html"]\n];'
catd_replacement = 'details/unc-nutrition-mph.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 追加
vd_new = ', "details/unc-mac.html", "details/unc-msm.html", "details/unc-meite.html", "details/unc-ssw-msw.html", "details/unc-nutrition-nfsh.html"'
vd_anchor = '"details/unc-nutrition-mph.html"]);'
vd_replacement = '"details/unc-nutrition-mph.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")
