import os, re, html

BASE = os.path.dirname(os.path.abspath(__file__))
tags = ["up-c0e9103", "yale-statistics", "cmu-c2ee442", "notre-ds", "mit-finance"]

def clean(raw):
    t = re.sub(r'<script[\s\S]*?</script>', ' ', raw)
    t = re.sub(r'<style[\s\S]*?</style>', ' ', t)
    t = re.sub(r'<[^>]+>', ' ', t)
    return html.unescape(re.sub(r'\s+', ' ', t)).strip()

for tag in tags:
    raw = open(os.path.join(BASE, f'_25_{tag}.txt'), encoding='utf-8').read()
    txt = clean(raw)
    print('='*30, tag, 'len', len(txt))
    # 关键词定位
    for kw in ['STEM', 'online', 'part-time', 'part time', 'hybrid', 'distance', 'residential', 'full-time', 'credit', 'requirement', 'Admission', 'deadline', 'TOEFL', 'IELTS', 'GRE', 'tuition', 'fee', 'curriculum', 'course']:
        idx = txt.lower().find(kw.lower())
        if idx >= 0:
            print(f'  [{kw}] ...{txt[max(0,idx-80):idx+180]}...')
    print()
