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

prog_entries = [
    '{id:"ut-c7a2833",s:"ut",n:"可持续管理硕士（MScSM）",en:"Master of Science in Sustainability Management",dept:"Graduate Unit: Management & Innovation",college:"密西沙加校区（UTM）",disc:"biz",lvl:"m",deg:"MScSM",dur:"SGS 页未列（待补）",stem:0,rank:"",test:{cls:""},ddl:"SGS 页未列具体轮次（待补）",lang:"TOEFL iBT / IELTS Academic（最低分待补）",tui:"SGS 页未列打包学费（待补）",url:"details/ut-c7a2833.html"}',
    '{id:"ut-c900110",s:"ut",n:"法务会计硕士（MFAcc）",en:"Master of Forensic Accounting",dept:"Graduate Unit: Management & Innovation",college:"密西沙加校区（UTM）",disc:"biz",lvl:"m",deg:"MFAcc",dur:"SGS 页未列（待补）",stem:0,rank:"",test:{cls:""},ddl:"SGS 页未列具体轮次（待补）",lang:"TOEFL iBT / IELTS Academic（最低分待补）",tui:"SGS 页未列打包学费（待补）",url:"details/ut-c900110.html"}',
    '{id:"ut-c4f263b",s:"ut",n:"应用计算硕士（MScAC）",en:"Master of Science in Applied Computing",dept:"Department of Computer Science",college:"文理学院（A&S）",disc:"cs",lvl:"m",deg:"MScAC",dur:"SGS 页未列（待补）",stem:1,rank:"",test:{cls:"rec"},ddl:"SGS 页未列具体轮次（待补）",lang:"TOEFL iBT / IELTS Academic（最低分待补）",tui:"SGS 页未列打包学费（待补）",url:"details/ut-c4f263b.html"}',
    '{id:"ut-c027862",s:"ut",n:"生物医学传播硕士（MScBMC）",en:"Master of Science in Biomedical Communications",dept:"Institute of Medical Science",college:"Temerty 医学院",disc:"med",lvl:"m",deg:"MScBMC",dur:"两年制 professional",stem:1,rank:"",test:{cls:""},ddl:"SGS 页未列具体轮次（待补）",lang:"IELTS 7.5 overall（6.5 each）；TOEFL 600 paper+5 TWE",tui:"SGS 页未列打包学费（待补）",url:"details/ut-c027862.html"}',
    '{id:"ut-ca0f935",s:"ut",n:"数学金融硕士（MMF）",en:"Master of Mathematical Finance",dept:"Graduate Unit: Mathematics",college:"文理学院（A&S）",disc:"biz",lvl:"m",deg:"MMF",dur:"SGS 页未列（待补）",stem:1,rank:"",test:{cls:""},ddl:"SGS 页未列具体轮次（待补）",lang:"TOEFL iBT / IELTS Academic（最低分待补）",tui:"SGS 页未列打包学费（待补）",url:"details/ut-ca0f935.html"}',
]

vd_new = [
    "details/ut-c7a2833.html",
    "details/ut-c900110.html",
    "details/ut-c4f263b.html",
    "details/ut-c027862.html",
    "details/ut-ca0f935.html",
]

# PROGRAMS 锚点：末条 jhu-c785e3d（无逗号）
prog_anchor = 'url:"details/jhu-c785e3d.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/jhu-c785e3d.html"}' + prog_new, 1)

# CATD 已有这5条，不重复追加

# VD 锚点
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")
