# -*- coding: utf-8 -*-
import re, io, sys, os
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
os.chdir(r"D:\work buddy\2026-11-05-14-15-52")
slugs=["nuclear-engineering-ms","environmental-engineering-ms","chemistry-ms","management-ms","psychology-ms"]
for s in slugs:
    txt=open(f"_50_{s}.html",encoding="utf-8").read()
    body=re.sub(r"<script[\s\S]*?</script>","",txt)
    body=re.sub(r"<style[\s\S]*?</style>","",body)
    print("===",s)
    # description
    d=re.search(r"<p>([^<]{40,500})</p>",body)
    if d: print("  DESC:",re.sub(r"\s+"," ",d.group(1)).strip()[:300])
    # total credit
    tc=re.search(r"[Tt]otal (?:Credit Hours|Credit Hours Required|Hours)\s*</td>\s*<td[^>]*>\s*([0-9]+)",body)
    if tc: print("  TOTAL CR:",tc.group(1))
    # flags
    for kw in ["MBA","Master of Business Administration","working professionals","part-time","online","distance learning","STEM"]:
        if kw.lower() in body.lower():
            idx=body.lower().find(kw.lower())
            ctx=re.sub(r"<[^>]+>"," ",body[max(0,idx-80):idx+150])
            print("  FLAG:",kw,"->",re.sub(r"\s+"," ",ctx).strip()[:200])
    # thesis/non-thesis
    for m in re.finditer(r"(Thesis|Non-?[Tt]hesis|Course[- ]Only|Option|Track|Concentration)",body):
        ctx=re.sub(r"<[^>]+>"," ",body[max(0,m.start()-50):m.end()+120])
        c=re.sub(r"\s+"," ",ctx).strip()
        if len(c)>30 and "Print Options" not in c and "showPrint" not in c and "showSection" not in c and "Designators" not in c:
            print("  OPT:",c[:160])
