# -*- coding: utf-8 -*-
import re, io, sys, collections
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
BASE = r"D:\work buddy\2026-11-05-14-15-52"
h = open(BASE + r"\index_main.html", encoding="utf-8").read()
p0 = h.index("const PROGRAMS=["); p1 = h.index("const CATD=[")
seg = h[p0:p1]
print("id count q", len(re.findall(r'\{id:"', seg)))
print("id count any", len(re.findall(r'\{id:', seg)))
# anchors not followed by double quote
for mm in re.finditer(r'\{id:[^"\n]{0,25}', seg):
    print("NONQ:", repr(mm.group(0)))
# find an id anchor without double quote
mm = re.search(r'\{id:[^\n]{0,30}', seg)
print("first anchor:", repr(mm.group(0)))
# locate anchors lacking double quote
anchors = [m.start() for m in re.finditer(r'\{id:', seg)]
for a in anchors[:5]:
    print("anchor:", repr(seg[a:a+40]))
print("head:", repr(seg[:150]))
heads = re.findall(r'(\}[\s,]*)\{id:', seg)
print("delim:", collections.Counter(repr(x) for x in heads))
# blocks by split on id anchor
parts = re.split(r'(?=\{id:")', seg)
print("split parts", len(parts))
