# -*- coding: utf-8 -*-
import io, sys, re, json
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
html = open("index_main.html", encoding="utf-8").read()

# PROGRAMS ids
progs = re.findall(r'\{id:"([^"]+)"', html)
print("PROGRAMS ids:", len(progs))
for p in progs:
    if p.startswith("cornell"):
        print("  ", p)

print("--- candidate dets occurrence in file ---")
cands = ["cornell-c1f30e8", "cornell-c60e314", "cornell-cffc740",
         "cornell-c8dae13", "cornell-ca5b01c", "cornell-cf3bfaf", "cornell-cdfe6e6"]
for d in cands:
    print(d, html.count(d))

# todo_upgrade.json 中 Cornell 条目
try:
    todo = json.load(open("todo_upgrade.json", encoding="utf-8"))
    items = todo if isinstance(todo, list) else todo.get("items", todo.get("todo", []))
    print("--- todo cornell entries ---")
    for it in items:
        if str(it.get("s", "")) == "cornell":
            print("  ", it.get("en"), "|", it.get("deg"), "|", it.get("det"), "|", it.get("url"))
except Exception as e:
    print("todo read err:", e)
