# -*- coding: utf-8 -*-
import io, sys, re, os, datetime, json
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
os.chdir(r"D:\work buddy\2026-11-05-14-15-52")
html = open("index_main.html", encoding="utf-8").read()

# 提取 PROGRAMS 段
m = re.search(r"const PROGRAMS=\[(.*?)\n\];", html, re.S)
seg = m.group(1)
# 按 {id:" 切分
chunks = seg.split('{id:"')[1:]
prog = {}
for c in chunks:
    pid = c.split('"', 1)[0]
    um = re.search(r'url:"(details/[^"]+)"', c)
    lm = re.search(r'lvl:"([md])"', c)
    nm = re.search(r'n:"([^"]*)"', c)
    if um:
        prog[um.group(1)] = {"id": pid, "lvl": lm.group(1) if lm else "?", "n": nm.group(1) if nm else ""}

def day(p):
    if not os.path.exists(p): return None
    return datetime.datetime.fromtimestamp(os.path.getmtime(p)).strftime("%Y-%m-%d")

by_day = {}
for url, info in prog.items():
    d = day(url)
    by_day.setdefault(d, []).append((url, info["id"], info["n"]))

for d in sorted(by_day, key=lambda x: (x is None, x)):
    print(f"== PROGRAMS 详情页 mtime {d}: {len(by_day[d])}")

for target in ("2026-11-16", "2026-11-17", "2026-11-18"):
    rows = by_day.get(target, [])
    print(f"\n### {target} PROGRAMS 命中 {len(rows)} 条")
    for url, pid, n in sorted(rows):
        print(" ", pid, "|", n[:40], "|", url)

# 17/18 落盘但不在 PROGRAMS 的 html（目录层占位/其他）
allh = [f"details\\{x}" for x in os.listdir("details") if x.endswith(".html")]
print("\n### 11-17/18 落盘但不在 PROGRAMS 的 html：")
for p in sorted(allh):
    d = day(p)
    if d in ("2026-11-17", "2026-11-18"):
        u = p.replace("\\", "/")
        if u not in prog:
            print(" ", d, u)

print("\nPROGRAMS 总数:", len(prog))
