# -*- coding: utf-8 -*-
"""第九十四轮：追加 5 条 Yale PROGRAMS + VD 登记"""
import re

with open("index_main.html", "r", encoding="utf-8") as f:
    html = f.read()

# 1. 定位 PROGRAMS 数组结束位置（括号深度匹配）
start = html.index("const PROGRAMS=[")
depth = 0
i = start + len("const PROGRAMS=")
end = None
while i < len(html):
    c = html[i]
    if c == '[':
        depth += 1
    elif c == ']':
        depth -= 1
        if depth == 0:
            end = i
            break
    i += 1
print(f"PROGRAMS 数组结束位置: {end}")
print(f"结束前 80 字符: ...{html[end-80:end]!r}")

# 5 条新记录
new_records = [
    # 1. Yale CBB MS
    '{id:"yale-cbb-ms",s:"yale",n:"计算生物学与生物医学信息",en:"M.S. in Computational Biology and Biomedical Informatics",dept:"Biomedical Informatics & Data Science",college:"GSAS",disc:"cs",lvl:"m",deg:"MS",dur:"2年全日制",stem:1,rank:"藤校跨学科",test:{cls:"GRE不接受（提交也不审）"},ddl:"12月1日",lang:"TOEFL iBT≥100 / IELTS≥7.0（口语≤7.5需8月英语课）",tui:"自费硕士，通常无奖学金",url:"details/yale-computational-biology-biomedical-informatics.html"},',
    # 2. Yale Stats DS MS
    '{id:"yale-stats-ds-ms",s:"yale",n:"统计与数据科学",en:"M.S. in Statistics and Data Science",dept:"Statistics & Data Science",college:"GSAS",disc:"stat",lvl:"m",deg:"MS",dur:"3学期（约1-1.5年）",stem:1,rank:"藤校统计热门",test:{cls:"GRE Optional"},ddl:"12月1日",lang:"TOEFL iBT / IELTS Academic",tui:"自费为主，每年约1000申请录40人",url:"details/yale-statistics-data-science.html"},',
    # 3. Yale ECE MS
    '{id:"yale-ece-ms",s:"yale",n:"电气与计算机工程",en:"M.S. in Electrical & Computer Engineering",dept:"Electrical & Computer Engineering",college:"SEAS",disc:"ee",lvl:"m",deg:"MS",dur:"1-2年",stem:1,rank:"藤校工程",test:{cls:"GRE Optional"},ddl:"12月15日（仅秋季）",lang:"TOEFL iBT / IELTS Academic",tui:"自费硕士",url:"details/yale-electrical-computer-engineering.html"},',
    # 4. Yale CS MS
    '{id:"yale-cs-ms",s:"yale",n:"计算机科学",en:"M.S. in Computer Science",dept:"Computer Science",college:"SEAS",disc:"cs",lvl:"m",deg:"MS",dur:"1年8门课",stem:1,rank:"藤校CS",test:{cls:"MS Required / PhD Not Accepted"},ddl:"1月2日（PhD为12月15日）",lang:"TOEFL iBT / IELTS Academic",tui:"自费硕士",url:"details/yale-computer-science.html"},',
    # 5. Yale BME MS
    '{id:"yale-bme-ms",s:"yale",n:"生物医学工程",en:"M.S. in Biomedical Engineering",dept:"Biomedical Engineering",college:"SEAS/Yale Med",disc:"bio",lvl:"m",deg:"MS",dur:"1-2年",stem:1,rank:"藤校BME",test:{cls:"MS Required / PhD Optional"},ddl:"12月15日（仅秋季）",lang:"TOEFL iBT / IELTS Academic",tui:"自费硕士，PhD全奖",url:"details/yale-biomedical-engineering.html"},',
]

insert_text = "\n  " + "\n  ".join(new_records)
html = html[:end] + insert_text + "\n" + html[end:]

# 2. 定位 VERIFIED_DETAILS 集合结束位置
vd_start = html.index("const VERIFIED_DETAILS=new Set([")
vd_end = html.index("])", vd_start)
print(f"VD 集合结束位置: {vd_end}")

new_vd = [
    "details/yale-computational-biology-biomedical-informatics.html",
    "details/yale-statistics-data-science.html",
    "details/yale-electrical-computer-engineering.html",
    "details/yale-computer-science.html",
    "details/yale-biomedical-engineering.html",
]
# 在结束前追加
vd_insert = ",".join(f'"{u}"' for u in new_vd) + ","
html = html[:vd_end] + vd_insert + html[vd_end:]

with open("index_main.html", "w", encoding="utf-8") as f:
    f.write(html)

print("\n✅ 已追加 5 条 PROGRAMS 记录")
print("✅ 已追加 5 条 VD 登记")
print(f"文件大小: {len(html)} 字符")
