# -*- coding: utf-8 -*-
import io,sys,ssl,urllib.request,re,html
sys.stdout=io.TextIOWrapper(sys.stdout.buffer,encoding="utf-8")
ctx=ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE
u="https://bulletin.stanford.edu/programs/CEE-MS"
t=urllib.request.urlopen(urllib.request.Request(u,headers={"User-Agent":"Mozilla/5.0"}),timeout=20,context=ctx).read().decode("utf-8","ignore")
c=html.unescape(re.sub(r"\s+"," ",re.sub(r"<[^>]+>"," ",re.sub(r"<script.*?</script>"," ",t,flags=re.S))))
# subplan titles
for m in re.finditer(r"([A-Z][A-Za-z/,&\- ]{3,40})\(Subplan\)",c):
    print("SUBPLAN:",m.group(1).strip())
print("\n=== online/part-time context ===")
for kw in ["online/on-campus","part-time student","Honors Cooperative","fully online","working full-time","Coterminal"]:
    k=c.lower().find(kw.lower())
    if k>=0:
        print("\n###",kw,"@",k,"\n",c[max(0,k-160):k+300])
print("\n=== overview five areas ===")
i=c.find("five areas")
print(c[i-120:i+500])
