# -*- coding: utf-8 -*-
"""Fix VD Set: move the 5 newly inserted URLs from outside the array to inside"""
import re
IDX = r"D:\work buddy\2026-11-05-14-15-52\index_main.html"
html = open(IDX, "r", encoding="utf-8").read()

# Current broken state: ...,"details/nyu-msqe.html"\n],"details/jhu-ma-econ.html","details/up-mse-ece.html","details/duke-mae.html","details/up-msmp.html","details/duke-msec.html");
# Desired state: ...,"details/nyu-msqe.html",\n  "details/jhu-ma-econ.html","details/up-mse-ece.html","details/duke-mae.html","details/up-msmp.html","details/duke-msec.html"]);

old = '"details/nyu-msqe.html"\n],"details/jhu-ma-econ.html","details/up-mse-ece.html","details/duke-mae.html","details/up-msmp.html","details/duke-msec.html")'
new = '"details/nyu-msqe.html",\n  "details/jhu-ma-econ.html","details/up-mse-ece.html","details/duke-mae.html","details/up-msmp.html","details/duke-msec.html"]'

if old in html:
    html = html.replace(old, new)
    open(IDX, "w", encoding="utf-8").write(html)
    print("OK: VD Set fixed")
else:
    print("Pattern not found; trying alternative...")
    # Try to find and fix by regex
    m = re.search(r'("details/nyu-msqe\.html")\s*\]\s*(,"details/jhu-ma-econ\.html"[^\)]*)\)', html)
    if m:
        replacement = m.group(1) + ',' + m.group(2).lstrip(',') + ']'
        html = html[:m.start()] + replacement + html[m.end():]
        open(IDX, "w", encoding="utf-8").write(html)
        print("OK: VD Set fixed via regex")
    else:
        print("ERROR: could not locate broken VD pattern")
