# -*- coding: utf-8 -*-
import re
h = open(r"D:\work buddy\2026-11-05-14-15-52\index_main.html", "r", encoding="utf-8").read()
# Find all occurrences of } immediately followed by { (no comma)
# Pattern: } followed by { but not ], and not already separated by comma
matches = list(re.finditer(r'\}\s*\{', h))
print("Found", len(matches), "} { patterns")
for m in matches:
    print("Offset", m.start(), ":", repr(h[m.start()-60:m.end()+40]))
# Fix: replace }{ with },{
# But be careful: only fix within PROGRAMS array (not in JS object literals elsewhere)
# Since PROGRAMS entries are all {id:"...",...}, the pattern } { between them is safe
fixed = re.sub(r'\}\s*\{', '},{', h)
# Count changes
diff = len(fixed) - len(h)
print("Fixed. Length diff:", diff)
open(r"D:\work buddy\2026-11-05-14-15-52\index_main.html", "w", encoding="utf-8").write(fixed)
