# -*- coding: utf-8 -*-
import re, sys, io, pathlib
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8", errors="replace")
BASE = pathlib.Path(r"D:\work buddy\2026-11-05-14-15-52")
H = BASE / "index_main.html"
html = H.read_text(encoding="utf-8")
seg_start = html.index("const PROGRAMS=[")
seg_end = html.index("const CATD=[")
seg = html[seg_start:seg_end]
VAL = {
 "gatech-cs-ms": "GRE（官网将 GRE 成绩列为评估项）",
 "gatech-analytics-ms": "官网未披露",
 "gatech-stat-ms": "官网未披露",
 "gatech-me-ms": "官网未披露",
 "gatech-bioinfo-ms": "官网未披露",
 "gatech-hci-ms": "官网未披露",
 "cornell-mps-acct": "官网未披露（项目页未列 GMAT/GRE 要求）",
 "nyu-msacc": "GMAT / GRE / EA 之一（可申请豁免，须预批）",
}
blocks = [b for b in re.split(r'(?=\bid:")', seg) if 'id:"' in b]
out = []
n = 0
for b in blocks:
    m = re.search(r'\bid:"([^"]+)"', b)
    pid = m.group(1) if m else ""
    if pid in VAL:
        nb, cnt = re.subn(r'(test\s*:\s*\{\s*cls\s*:\s*)"([^"]*)"', lambda mm: mm.group(1) + '"' + VAL[pid] + '"', b, count=1)
        if cnt:
            out.append(nb); n += 1
            print("patched", pid)
        else:
            print("NO test.cls", pid); out.append(b)
    else:
        out.append(b)
first = seg.index('id:"')
new_seg = seg[:first] + "".join(out)
if not new_seg.endswith("\n"):
    new_seg += "\n"
html2 = html[:seg_start] + new_seg + html[seg_end:]
H.write_text(html2, encoding="utf-8")
print("patched", n, "bytes", H.stat().st_size, "}{", html2.count("}{"))
