# -*- coding: utf-8 -*-
import io, re
h = io.open('index_main.html', encoding='utf-8').read()
seg = re.search(r'PROGRAMS\s*=\s*\[(.*?)\n\s*\];', h, re.S).group(1)
T = ['ut-ece-phd', 'ut-stat-phd', 'ucsd-ece-phd', 'ucsd-mae-phd', 'uchicago-cs-phd',
     'uchicago-econ-phd', 'uchicago-booth-fin-phd', 'uchicago-bms']
for t in T:
    m = re.search('{id:"' + t + '"', seg)
    if not m:
        print(t, 'NOTFOUND'); continue
    nxt = seg.find('{id:"', m.end())
    blk = seg[m.start(): nxt if nxt > 0 else len(seg)]
    u = re.search('url:"([^"]*)"', blk)
    n = re.search('n:"([^"]*)"', blk)
    print(t, '|', u.group(1) if u else 'NOURL', '|', n.group(1) if n else '')
