# -*- coding: utf-8 -*-
"""Compact summary of a JHU courseleaf program page: intro, key bullets, course codes."""
import io, re, sys, os
sys.path.insert(0, r"D:\work buddy\2026-11-05-14-15-52")
from _r349_panel import panel, BASE

f = sys.argv[1]
if not os.path.isabs(f):
    cand = os.path.join(BASE, "cache", f)
    if os.path.exists(cand):
        f = cand
    else:
        import glob
        g = glob.glob(os.path.join(BASE, "cache", "*" + f + "*")) or glob.glob(os.path.join(BASE, "cache", f[:40] + "*"))
        f = g[0]
t = io.open(f, encoding="utf-8", errors="ignore").read()
ov = panel(t, "textcontainer")
lines = [l.strip() for l in ov.split("\n") if l.strip()]
print("LEN", len(ov))
print("== INTRO ==")
body = []
for l in lines:
    if l.startswith('id="textcontainer"'):
        continue
    body.append(l)
print("\n".join(body[:14])[:1800])
print("\n== KEY LINES ==")
for l in body:
    if re.search(r'credit|semester|three semesters|degree|required|Required|prerequisit|GPA|admission|STEM', l) and len(l) < 260:
        print("-", l)
print("\n== CODES ==")
code_lines = []
cl = re.compile(r'^(?:EN|AS|BU|PH|ME|PY|SA)\.\d{3}\.\d{3}[A-Z]?$')
for i, l in enumerate(body):
    if cl.match(l):
        nxt = body[i + 1] if i + 1 < len(body) else ""
        code_lines.append(l + " | " + nxt[:90])
seen = []
for c in code_lines:
    if c not in seen:
        seen.append(c)
print(len(seen), "unique code rows")
print("\n".join(seen[:60]))
