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

# 5 条 PROGRAMS entry（每条末尾带逗号，和现有格式一致）
entries = [
    '{id:"up-dsai-mse",s:"up",n:"数据科学与人工智能工程硕士",en:"MSE in Data Science & Artificial Intelligence",dept:"SEAS · CIS 计算机与信息科学系 / ESE 电气与系统工程系",college:"SEAS 工程学院",disc:"cs",lvl:"m",deg:"MSE",dur:"10 CU · 1.5–2 年 full-time，含 thesis 或 practicum",stem:1,rank:"数据科学/AI STEM-designated",test:{cls:""},ddl:"",lang:"",tui:"",url:"details/up-dsai-mse.html"},',
    '{id:"up-mascs",s:"up",n:"计算机科学应用硕士（非 CS 背景转 CS）",en:"Master of Applied Science in Computer Science (MAS-CS)",dept:"SEAS · CIS 计算机与信息科学系",college:"SEAS 工程学院",disc:"cs",lvl:"m",deg:"MAS",dur:"10 CU · 2 年 full-time，On-Campus 路径",stem:1,rank:"SEAS 工程类 STEM-designated",test:{cls:""},ddl:"",lang:"",tui:"",url:"details/up-mascs.html"},',
    '{id:"up-scicomp-mse",s:"up",n:"科学计算工程硕士",en:"MSE in Scientific Computing",dept:"SEAS · ENM / CIS / AMCS",college:"SEAS 工程学院",disc:"cs",lvl:"m",deg:"MSE",dur:"10 CU · 2 年 full-time，含 thesis 或 independent study",stem:1,rank:"科学计算/数值方法 STEM-designated",test:{cls:""},ddl:"",lang:"",tui:"",url:"details/up-scicomp-mse.html"},',
    '{id:"up-mbds",s:"up",n:"行为与决策科学硕士",en:"Master of Behavioral and Decision Sciences (MBDS)",dept:"SAS · College of Liberal and Professional Studies (LPS)",college:"Penn SAS 文理学院",disc:"soc",lvl:"m",deg:"MBDS",dur:"9 CU · 1 学年 full-time，含 Capstone",stem:0,rank:"行为经济/决策科学/公共政策跨学科",test:{cls:""},ddl:"",lang:"",tui:"",url:"details/up-mbds.html"},',
    '{id:"up-biostat-ms",s:"up",n:"生物统计硕士",en:"MS in Biostatistics",dept:"Perelman 医学院 · GGEB 研究生组",college:"Perelman School of Medicine",disc:"med",lvl:"m",deg:"MS",dur:"12 CU · 2 年 full-time，含 Master Thesis",stem:1,rank:"生物统计/统计类 STEM-designated，研究型 MS",test:{cls:""},ddl:"",lang:"",tui:"",url:"details/up-biostat-ms.html"},',
]
new_prog = "\n" + "\n".join(entries) + "\n"

# PROGRAMS 追加：锚点保留 up-mbiot 的 url 字段，在后面追加
prog_anchor = 'url:"details/up-mbiot.html"},\n];'
assert prog_anchor in idx, "PROGRAMS anchor not found"
prog_replacement = 'url:"details/up-mbiot.html"},' + new_prog + '];'
idx = idx.replace(prog_anchor, prog_replacement, 1)

# CATD 追加
catd_entries = [
    '["up","SEAS · CIS 系 / ESE 系","MSE in Data Science & Artificial Intelligence","数据科学与人工智能工程硕士","MSE","https://catalog.upenn.edu/graduate/programs/data-science-artificial-intelligence-mse/","cs","details/up-dsai-mse.html"],',
    '["up","SEAS · CIS 系","Master of Applied Science in Computer Science (MAS-CS)","计算机科学应用硕士（非 CS 背景转 CS）","MAS","https://catalog.upenn.edu/graduate/programs/computer-science-mascs/","cs","details/up-mascs.html"],',
    '["up","SEAS · ENM / CIS / AMCS","MSE in Scientific Computing","科学计算工程硕士","MSE","https://catalog.upenn.edu/graduate/programs/scientific-computing-mse/","cs","details/up-scicomp-mse.html"],',
    '["up","SAS · LPS 学院","Master of Behavioral and Decision Sciences (MBDS)","行为与决策科学硕士","MBDS","https://catalog.upenn.edu/graduate/programs/behavioral-decision-sciences-mbds/","soc","details/up-mbds.html"],',
    '["up","Perelman 医学院 · GGEB","MS in Biostatistics","生物统计硕士","MS","https://catalog.upenn.edu/graduate/programs/epidemiology-biostatistics-biostatistics-ms/","med","details/up-biostat-ms.html"],',
]
new_catd = "\n" + "\n".join(catd_entries) + "\n"
catd_anchor = '"details/up-mbiot.html"],\n];'
assert catd_anchor in idx, "CATD anchor not found"
catd_replacement = '"details/up-mbiot.html"],' + new_catd + '];'
idx = idx.replace(catd_anchor, catd_replacement, 1)

# VD 追加
vd_anchor = '"details/up-mbiot.html"]);'
assert vd_anchor in idx, "VD anchor not found"
vd_new = '"details/up-mbiot.html", "details/up-dsai-mse.html", "details/up-mascs.html", "details/up-scicomp-mse.html", "details/up-mbds.html", "details/up-biostat-ms.html"]);'
idx = idx.replace(vd_anchor, vd_new, 1)

open(p, "w", encoding="utf-8").write(idx)
print("APPENDED 5 PROGRAMS + 5 CATD + 5 VD")
