# -*- coding: utf-8 -*-
import sys, io, re, os
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
BASE = r"D:\work buddy\2026-11-05-14-15-52"
s = open(BASE + r"\index_main.html", encoding="utf-8").read()
a = s.index("const PROGRAMS=["); b = s.index("const CATD=["); seg = s[a:b]
# 现有 ucsd 已填 tui 的样例
for pid in ["ucsd-ece-ms","ucsd-cs-ms","ucsd-cse-ms"]:
    m = re.search(r'\{id:"' + pid + r'"[\s\S]*?(?=\}\s*,?\s*\{id:"|\}\s*\])', seg)
    if m:
        t = m.group(0)
        tm = re.search(r'tui:"([^"]*)"', t)
        print(pid, "->", tm.group(1) if tm else "NONE")
# 采样 3 条已有 tui 的 ucsd
cnt = 0
for pid, body in re.findall(r'\{id:"([^"]+)"([\s\S]*?)(?=\}\s*,?\s*\{id:"|\}\s*\]|,?\s*\];)', seg):
    if pid.startswith("ucsd"):
        tm = re.search(r'tui:"([^"]*)"', body)
        if tm and tm.group(1):
            print("SAMPLE", pid, "|", tm.group(1))
            cnt += 1
            if cnt >= 6: break
print("=== 详情页费用块 ===")
for pid in ["ucsd-cse-ms","ucsd-mae-ms","ucsd-se-ms","ucsd-math-app-ms","ucsd-bioe","ucsd-bioe-med-ms","ucsd-css-ms","ucsd-cse-cpss-ms"]:
    fp = os.path.join(BASE, "details", pid + ".html")
    if not os.path.exists(fp):
        print("!! no file", pid); continue
    txt = open(fp, encoding="utf-8").read()
    print("---", pid, os.path.getsize(fp), "bytes")
    for ln in txt.split("\n"):
        if re.search(r"学费|Tuition|tuition|费用", ln):
            print("   ", ln.strip()[:160])
