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

# 1. Replace PROGRAMS up-msgc entry with up-higher-ed-msed
old_prog = '{id:"up-msgc",s:"up",n:"遗传咨询理学硕士",en:"MS in Genetic Counseling",dept:"Perelman 医学院",college:"Perelman School of Medicine",disc:"med",lvl:"m",deg:"MSGC",dur:"18.5 CU · 含临床实习与 Thesis",stem:1,rank:"遗传咨询/基因组学类，ACGC 认证项目",test:{cls:""},ddl:"",lang:"",tui:"",url:"details/up-msgc.html"},'
new_prog = '{id:"up-higher-ed-msed",s:"up",n:"高等教育文学硕士",en:"M.S.Ed. in Higher Education",dept:"GSE 教育学院 · 高等教育系",college:"Graduate School of Education",disc:"edu",lvl:"m",deg:"M.S.Ed.",dur:"全日制，提供 graduate assistantship",stem:0,rank:"高等教育管理/学生事务类，GSE 教育学院",test:{cls:""},ddl:"",lang:"",tui:"",url:"details/up-higher-ed-msed.html"},'
assert old_prog in idx, "old PROGRAMS entry not found"
idx = idx.replace(old_prog, new_prog, 1)

# 2. Replace CATD up-msgc row
old_catd = '["up","Perelman 医学院","MS in Genetic Counseling","遗传咨询理学硕士","MSGC","https://catalog.upenn.edu/graduate/programs/genetic-counseling-msgc/","med","details/up-msgc.html"],'
new_catd = '["up","GSE 教育学院 · 高等教育系","M.S.Ed. in Higher Education","高等教育文学硕士","M.S.Ed.","https://catalog.upenn.edu/graduate/programs/higher-education-msed/","edu","details/up-higher-ed-msed.html"],'
assert old_catd in idx, "old CATD row not found"
idx = idx.replace(old_catd, new_catd, 1)

# 3. Replace VD entry
old_vd = '"details/up-msgc.html"'
new_vd = '"details/up-higher-ed-msed.html"'
assert old_vd in idx, "old VD entry not found"
idx = idx.replace(old_vd, new_vd, 1)

open("index_main.html", "w", encoding="utf-8").write(idx)
print("REPLACED up-msgc -> up-higher-ed-msed in PROGRAMS/CATD/VD")

# remove orphan det
try:
    os.remove("details/up-msgc.html")
    print("removed orphan details/up-msgc.html")
except Exception as e:
    print("rm orphan:", e)
