# -*- coding: utf-8 -*-
"""追加 Stanford：SCHOOLS 一行 + CATD 108 行。"""
import io, sys, os, json
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")
r = open(F, encoding="utf-8").read()
catd = json.load(open(os.path.join(BASE, "pending_stanford_catd.json"), encoding="utf-8"))

school_anchor = ' {id:"caltech",cn:"加州理工学院",en:"California Institute of Technology",country:"US",qs:"2027 USNews 并列第 5"},\n];'
assert school_anchor in r, "SCHOOLS 锚点未找到"
r = r.replace(school_anchor,
              ' {id:"caltech",cn:"加州理工学院",en:"California Institute of Technology",country:"US",qs:"2027 USNews 并列第 5"},\n'
              ' {id:"stanford",cn:"斯坦福大学",en:"Stanford University",country:"US",qs:"2027 USNews 并列第 5"},\n];')

last = '["caltech", "人文与社会科学分部", "Social Science", "社会科学", "PhD", "https://catalog.caltech.edu/current/information-for-graduate-students/special-regulations-for-graduate-options/social-science-ss/", "soc", "details/caltech-social-science.html"],\n];'
assert last in r, "CATD 末尾锚点未找到"
def fmt(c):
    return f'["{c[0]}", "{c[1]}", "{c[2]}", "{c[3]}", "{c[4]}", "{c[5]}", "{c[6]}", "{c[7]}"],'
new_rows = "\n".join(fmt(c) for c in catd)
r = r.replace(last,
              '["caltech", "人文与社会科学分部", "Social Science", "社会科学", "PhD", "https://catalog.caltech.edu/current/information-for-graduate-students/special-regulations-for-graduate-options/social-science-ss/", "soc", "details/caltech-social-science.html"],\n'
              + new_rows + "\n];")

open(F, "w", encoding="utf-8", newline="").write(r)
print("SCHOOLS stanford 已加；CATD 追加", len(catd), "行")
