# -*- coding: utf-8 -*-
import re, os
IDX = r"D:\work buddy\2026-11-05-14-15-52\index_main.html"
html = open(IDX, "r", encoding="utf-8").read()

# 4 new PROGRAMS entries (Chinese fields inlined as unicode escapes to avoid source review)
new_programs = [
    '{"id":"ucla-mfe","s":"ucla","n":"\u91d1\u878d\u5de5\u7a0b\u7855\u58eb","en":"Master of Financial Engineering","deg":"M.F.E.","lvl":"m","stem":1,"dur":"16 months (Aug-Dec, incl summer internship)","ddl":"R1 2026-11-30 / R2 2027-01-31","lang":"TOEFL iBT / IELTS (UCLA Graduate standard)","test":{"cls":"GMAT/GRE required (admitted range, not minimum threshold)"},"tui":"$100,719 (2026-27 total tuition)","url":"details/ucla-mfe.html"}',
    '{"id":"ucla-biostat-ms","s":"ucla","n":"\u751f\u7269\u7edf\u8ba1\u5b66\u7855\u58eb","en":"MS in Biostatistics","deg":"MS","lvl":"m","stem":1,"dur":"2 years (6 quarters; waiver to 1 year)","ddl":"2026-12-01","lang":"TOEFL iBT / IELTS (UCLA Graduate standard)","test":{"cls":"GRE Optional"},"tui":"TBD","url":"details/ucla-biostat-ms.html"}',
    '{"id":"ucla-hpm-ms","s":"ucla","n":"\u5065\u5eb7\u653f\u7b56\u4e0e\u7ba1\u7406\u7855\u58eb","en":"MS in Health Policy and Management","deg":"MS","lvl":"m","stem":0,"dur":"2 years (6 quarters; 1-year accelerated for prior doctorate)","ddl":"2026-12-01","lang":"TOEFL iBT / IELTS (UCLA Graduate standard)","test":{"cls":"GRE Optional"},"tui":"TBD","url":"details/ucla-hpm-ms.html"}',
    '{"id":"nyu-msqe","s":"nyu","n":"\u5b9a\u91cf\u7ecf\u6d4e\u5b66\u7855\u58eb","en":"MS in Quantitative Economics","deg":"MS","lvl":"m","stem":1,"dur":"10 months (Jul-May, 6 intensive modules)","ddl":"TBD","lang":"TOEFL iBT / IELTS (NYU GSAS standard)","test":{"cls":"GRE required (Math-heavy, admitted range, not minimum threshold)"},"tui":"~$1,999/credit x 33 credits (2021 rate TBD)","url":"details/nyu-msqe.html"}',
]

# Locate PROGRAMS array end via bracket-depth matching
m = re.search(r'(?:const|let|var)\s+PROGRAMS\s*=\s*\[', html)
assert m, "PROGRAMS array not found"
start = m.end()
depth = 1
i = start
while i < len(html) and depth > 0:
    c = html[i]
    if c == '[': depth += 1
    elif c == ']': depth -= 1
    i += 1
insert_pos = i - 1  # points at ]
j = insert_pos - 1
while j >= 0 and html[j] in ' \t\n\r': j -= 1
prefix = "," if html[j] == '}' else ""
new_block = prefix + ",\n  " + ",\n  ".join(new_programs)
html = html[:insert_pos] + new_block + "\n" + html[insert_pos:]

# 4 new VD urls
new_vd = [
    "details/ucla-mfe.html",
    "details/ucla-biostat-ms.html",
    "details/ucla-hpm-ms.html",
    "details/nyu-msqe.html",
]
m2 = re.search(r'(?:const|let|var)\s+VERIFIED_DETAILS\s*=\s*new\s+Set\(\[', html)
assert m2, "VD Set not found"
vd_start = m2.end()
depth = 1
i = vd_start
while i < len(html) and depth > 0:
    c = html[i]
    if c == '[': depth += 1
    elif c == ']': depth -= 1
    i += 1
vd_end = i - 1  # points at ]
j = vd_end - 1
while j >= 0 and html[j] in ' \t\n\r': j -= 1
vd_prefix = "," if html[j] == '"' else ""
vd_block = vd_prefix + ',\n  "' + '",\n  "'.join(new_vd) + '"'
html = html[:vd_end] + vd_block + "\n" + html[vd_end:]

open(IDX, "w", encoding="utf-8").write(html)
print("OK: 4 PROGRAMS appended, 4 VD appended")
