# -*- coding: utf-8 -*-
import io, sys, re, json, os
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
BASE = r"D:\work buddy\2026-11-05-14-15-52"
F = os.path.join(BASE, "index_main.html")
html = open(F, encoding="utf-8").read()

NEW_ID = "notre-mscse"
NEW_DET = "details/notre-mscse.html"

entry = (
    '{id:"notre-mscse",s:"notre",n:"计算机科学与工程硕士",'
    'en:"Master of Science in Computer Science and Engineering (MSCSE)",'
    'dept:"计算机科学与工程系（CSE）· 工程学院",'
    'college:"College of Engineering, University of Notre Dame",'
    'disc:"cs",lvl:"m",deg:"MS",'
    'dur:"11 个月（两学期 + 暑期），全日制在校；项目或论文；最低一学期在校",'
    'stem:0,rank:"2027 USNews 第 20",'
    ' test:{cls:"opt"},'
    'ddl:"Fall：12 月 15 日；Spring：10 月 15 日（官网列月份日期未标年份；按 2027 申请季：2027 秋 2026-12-15、2027 春 2026-10-15）",'
    'lang:"TOEFL / IELTS / Duolingo（非英语母语；项目页未公布最低总分/小分门槛）",'
    'tui:"项目页、CSE 系站与研究生院招生页未公布项目级学费/杂费费率与总额，留空不估算；硕士项目级资助名额/金额官网未单列",'
    ' url:"details/notre-mscse.html"},'
)

changed = False

# 1) PROGRAMS 幂等追加
if 'id:"' + NEW_ID + '"' not in html:
    anchor = 'url:"details/uw-c1c6744.html"},];'
    assert anchor in html, "末条锚点未变，需人工核对"
    replacement = 'url:"details/uw-c1c6744.html"},\n' + entry + '\n];'
    html = html.replace(anchor, replacement, 1)
    changed = True
    print("PROGRAMS 追加:", NEW_ID)
else:
    print("PROGRAMS 已存在:", NEW_ID, "跳过")

# 2) VD 集合幂等登记
if NEW_DET not in html:
    vd_anchor = 'const VERIFIED_DETAILS=new Set(["details/uw-c1c6744.html"'
    assert vd_anchor in html, "VD 锚点未变"
    html = html.replace(vd_anchor, 'const VERIFIED_DETAILS=new Set(["' + NEW_DET + '","details/uw-c1c6744.html"', 1)
    changed = True
    print("VD 登记:", NEW_DET)
else:
    print("VD 已登记:", NEW_DET, "跳过")

if changed:
    open(F, "w", encoding="utf-8", newline="").write(html)
    print("已写回 index_main.html")
else:
    print("无变更，未写回")
