# -*- coding: utf-8 -*-
import sys, io, 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 = open("index_main.html", encoding="utf-8").read()

def entry(e):
    return ('{id:"%s",s:"%s",n:"%s",en:"%s",dept:"%s",college:"%s",disc:"%s",lvl:"%s",deg:"%s",'
            'dur:"",stem:%d,rank:"",test:{cls:""},ddl:"",lang:"",tui:"",url:"%s"},'
            % (e["id"],e["s"],e["n"],e["en"],e["dept"],e["college"],e["disc"],e["lvl"],e["deg"],e["stem"],e["url"]))

new = [{
    "id":"usc-cmb","s":"usc","n":"计算分子生物学","en":"Master of Science in Computational Molecular Biology",
    "dept":"Dept of Quantitative and Computational Biology (QCB)","college":"Dornsife 文理学院",
    "disc":"sci","lvl":"m","deg":"MS","stem":1,"url":"details/usc-cmb.html"
}]

# 1) PROGRAMS append
anchor = 'url:"details/usc-cca84a1.html"},\n];'
assert anchor in idx, "PROGRAMS anchor missing"
block = "".join(entry(e) for e in new)
idx = idx.replace(anchor, 'url:"details/usc-cca84a1.html"},' + block + '\n];', 1)

# 2) CATD append (CMB not in CATD, add row)
catd_anchor = '"details/unc-mpp.html"]\n];'
assert catd_anchor in idx, "CATD anchor missing"
catd_row = '["usc", "Dornsife 文理学院 QCB 系", "Computational Molecular Biology", "计算分子生物学", "MS", "https://www.qcb-dornsife.usc.edu/masters", "sci", "details/usc-cmb.html"],'
idx = idx.replace(catd_anchor, '"details/unc-mpp.html"],\n' + catd_row + '\n];', 1)

# 3) VD append
vd_marker = "const VERIFIED_DETAILS=new Set(["
vs = idx.find(vd_marker)
assert vs > 0, "VD marker missing"
ve = idx.find("]);", vs)
assert ve > vs
# insert before ]
idx = idx[:ve] + ', "details/usc-cmb.html"' + idx[ve:]

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