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

# 5 条 PROGRAMS 记录（字符串拼接，不用 % 格式化）
new_entries = [
 '{id:"ut-cs-msc",s:"ut",n:"计算机科学硕士（MSc）",en:"Master of Science in Computer Science",dept:"Department of Computer Science",college:"Faculty of Arts & Science",disc:"cs",lvl:"m",deg:"MSc",dur:"研究型硕士（thesis）",stem:0,rank:"",test:{cls:"notreq"},ddl:"待补（SGS 项目页）",lang:"待补（TOEFL/IELTS 最低分）",tui:"打包学费待补",url:"details/ut-c863142.html"},',
 '{id:"ut-msac",s:"ut",n:"应用计算理学硕士（MScAC）",en:"Master of Science in Applied Computing",dept:"Department of Computer Science",college:"Faculty of Arts & Science",disc:"cs",lvl:"m",deg:"MScAC",dur:"授课型专业硕士（含产业项目）",stem:0,rank:"",test:{cls:"rec"},ddl:"待补（SGS 项目页）",lang:"待补（TOEFL/IELTS 最低分）",tui:"打包学费待补",url:"details/ut-c4f263b.html"},',
 '{id:"ut-ph-msc",s:"ut",n:"公共卫生硕士 / 公共卫生科学理学硕士（MPH / MSc）",en:"Master of Public Health / Master of Science in Public Health Sciences",dept:"Dalla Lana School of Public Health",college:"Dalla Lana School of Public Health",disc:"med",lvl:"m",deg:"MPH/MSc",dur:"授课型专业硕士 MPH / 研究型 MSc",stem:0,rank:"",test:{cls:"notreq"},ddl:"待补（SGS 项目页）",lang:"待补（TOEFL/IELTS 最低分）",tui:"打包学费待补",url:"details/ut-c6baa60.html"},',
 '{id:"ut-kine-msc",s:"ut",n:"运动机能学理学硕士（MSc）",en:"Master of Science in Kinesiology",dept:"School of Kinesiology",college:"Faculty of Kinesiology and Physical Education",disc:"med",lvl:"m",deg:"MSc",dur:"研究型硕士（thesis，须自行联系导师）",stem:0,rank:"",test:{cls:"notreq"},ddl:"待补（SGS 项目页）",lang:"待补（TOEFL/IELTS 最低分）",tui:"打包学费待补",url:"details/ut-kine-msc.html"},',
 '{id:"ut-nutr-msc",s:"ut",n:"营养科学理学硕士（MSc）",en:"Master of Science in Nutritional Sciences",dept:"Department of Nutritional Sciences",college:"Faculty of Medicine",disc:"med",lvl:"m",deg:"MSc",dur:"研究型硕士（录取后自行联系导师）",stem:0,rank:"",test:{cls:"notreq"},ddl:"待补（SGS 项目页）",lang:"待补（TOEFL/IELTS 最低分）",tui:"打包学费待补",url:"details/ut-nutr-msc.html"},',
]

# 1. PROGRAMS：在末条 ut-c3a91ad.html"},\n  之后、]; 之前插入
anchor_prog = 'url:"details/ut-c3a91ad.html"},\n];'
assert anchor_prog in idx, "PROGRAMS anchor not found"
new_prog_block = 'url:"details/ut-c3a91ad.html"},\n' + "\n".join(new_entries) + "\n];"
idx = idx.replace(anchor_prog, new_prog_block, 1)

# 2. VD：在 VD 段的 ]; 前插入 5 个 det
vd_start = idx.find("const VERIFIED_DETAILS=new Set([")
vd_end = idx.find("]);", vd_start)
# vd_end 指向 ] 位置（]); 的 ]），在 ] 之前插入
vd_new_dets = ',"details/ut-c863142.html","details/ut-c4f263b.html","details/ut-c6baa60.html","details/ut-kine-msc.html","details/ut-nutr-msc.html"'
idx = idx[:vd_end] + vd_new_dets + idx[vd_end:]

# 3. CATD 补 2 条（kinesiology / nutritional-sciences）
# CATD 段末条 ]; 前插入
catd_start = idx.find("const CATD=")
catd_end = idx.find("];", catd_start)
catd_new = '["ut","运动机能学与体育学院","Kinesiology","运动机能学","MSc","https://www.sgs.utoronto.ca/programs/kinesiology/","med","details/ut-kine-msc.html"],\n["ut","营养科学系（医学院）","Nutritional Sciences","营养科学","MSc","https://www.sgs.utoronto.ca/programs/nutritional-sciences/","med","details/ut-nutr-msc.html"],'
idx = idx[:catd_end] + catd_new + "\n" + idx[catd_end:]

open("index_main.html","w",encoding="utf-8").write(idx)
print("DONE. file size:", len(idx))

# ast 验证追加脚本本身（不执行）
src=open(__file__,encoding="utf-8").read()
ast.parse(src)
print("script syntax OK")
