# -*- coding: utf-8 -*-
import io, sys, os, re, ast
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
os.chdir(r"D:\work buddy\2026-11-05-14-15-52")

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

# 4 条 PROGRAMS 记录
prog_entries = [
    '{id:"unc-mha",s:"unc",n:"卫生管理硕士（MHA）",en:"Master of Health Administration",dept:"Department of Health Policy and Management",college:"Gillings School of Global Public Health",disc:"med",lvl:"m",deg:"MHA",dur:"catalog 页未列（待补）",stem:0,rank:"",test:{cls:""},ddl:"catalog 页未列具体轮次（待补）",lang:"TOEFL iBT / IELTS Academic（最低分待补）",tui:"catalog 页未列打包学费（待补）",url:"details/unc-mha.html"}',
    '{id:"unc-maps",s:"unc",n:"应用职业研究硕士（MAPS）",en:"Master of Applied Professional Studies",dept:"The Graduate School",college:"The Graduate School",disc:"biz",lvl:"m",deg:"MAPS",dur:"catalog 页未列（待补）",stem:0,rank:"",test:{cls:"notreq"},ddl:"catalog 页未列具体轮次（待补）",lang:"TOEFL iBT / IELTS Academic（最低分待补）",tui:"catalog 页未列打包学费（待补）",url:"details/unc-maps.html"}',
    '{id:"unc-global-studies-ma",s:"unc",n:"全球研究文学硕士（MA）",en:"Master of Arts in Global Studies",dept:"Center for Global Studies",college:"College of Arts and Sciences",disc:"soc",lvl:"m",deg:"MA",dur:"36 学分",stem:0,rank:"",test:{cls:""},ddl:"catalog 页未列具体轮次（待补）",lang:"TOEFL iBT / IELTS Academic（最低分待补）",tui:"catalog 页未列打包学费（待补）",url:"details/unc-global-studies-ma.html"}',
    '{id:"unc-media-comm-ma",s:"unc",n:"媒体与传播文学硕士（MA）",en:"Master of Arts in Media and Communication",dept:"School of Media and Journalism",college:"School of Media and Journalism",disc:"soc",lvl:"m",deg:"MA",dur:"catalog 页未列（待补）",stem:0,rank:"",test:{cls:""},ddl:"catalog 页未列具体轮次（待补）",lang:"TOEFL iBT / IELTS Academic（最低分待补）",tui:"catalog 页未列打包学费（待补）",url:"details/unc-media-comm-ma.html"}',
]

# 4 条 CATD 记录
catd_entries = [
    '["unc", "Gillings School of Global Public Health", "Master of Health Administration", "卫生管理硕士", "MHA", "https://catalog.unc.edu/graduate/schools-departments/health-policy-management/", "med", "details/unc-mha.html"]',
    '["unc", "The Graduate School", "Master of Applied Professional Studies", "应用职业研究硕士", "MAPS", "https://catalog.unc.edu/graduate/schools-departments/applied-professional-studies/", "biz", "details/unc-maps.html"]',
    '["unc", "College of Arts and Sciences", "Master of Arts in Global Studies", "全球研究文学硕士", "MA", "https://catalog.unc.edu/graduate/schools-departments/global-studies/", "soc", "details/unc-global-studies-ma.html"]',
    '["unc", "School of Media and Journalism", "Master of Arts in Media and Communication", "媒体与传播文学硕士", "MA", "https://catalog.unc.edu/graduate/schools-departments/media-journalism/", "soc", "details/unc-media-comm-ma.html"]',
]

# VD 新 det 列表
vd_new = [
    "details/unc-mha.html",
    "details/unc-maps.html",
    "details/unc-global-studies-ma.html",
    "details/unc-media-comm-ma.html",
]

# PROGRAMS 锚点：末条 unc-nutrition-nfsh
prog_anchor = 'url:"details/unc-nutrition-nfsh.html"}\n];'
assert prog_anchor in idx, "PROGRAMS anchor not found"
prog_new = ",\n" + ",\n".join(prog_entries) + "\n];"
idx = idx.replace(prog_anchor, 'url:"details/unc-nutrition-nfsh.html"}' + prog_new, 1)

# CATD 锚点：末条 unc-nutrition-nfsh
catd_anchor = 'details/unc-nutrition-nfsh.html"]\n];'
assert catd_anchor in idx, "CATD anchor not found"
catd_new = ",\n" + ",\n".join(catd_entries) + "\n];"
idx = idx.replace(catd_anchor, 'details/unc-nutrition-nfsh.html"]' + catd_new, 1)

# VD 锚点：在 const VERIFIED_DETAILS=new Set([...]) 段内
vd_start = idx.find("const VERIFIED_DETAILS=new Set([")
assert vd_start > 0, "VD start not found"
vd_end = idx.find("]);", vd_start)
assert vd_end > 0, "VD end not found"
vd_insert = ", " + ", ".join(['"' + d + '"' for d in vd_new])
idx = idx[:vd_end] + vd_insert + idx[vd_end:]

# 写回
with open("index_main.html", "w", encoding="utf-8") as f:
    f.write(idx)
print("APPENDED OK")
