# -*- coding: utf-8 -*-
import sys, io, concurrent.futures as cf
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
import requests
requests.packages.urllib3.disable_warnings()

UA = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0 Safari/537.36",
      "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
      "Accept-Language": "en-US,en;q=0.9"}

urls = [
 ("umich-ro","https://ro.umich.edu/tuition-fees"),
 ("umich-stuacct","https://studentaccounts.umich.edu/"),
 ("cornell-tuition","https://tuition.cornell.edu/"),
 ("cornell-dfa","https://www.dfa.cornell.edu/"),
 ("col-gsas","https://gsas.columbia.edu/"),
 ("col-stat-root","https://stat.columbia.edu/"),
 ("col-tuition","https://www.columbia.edu/content/tuition-costs"),
 ("princeton-grad","https://gradschool.princeton.edu/"),
 ("upenn-sfs","https://srfs.upenn.edu/costs-budgeting"),
 ("upenn-provost","https://provost.upenn.edu/"),
 ("gatech-bursar","https://www.bursar.gatech.edu/"),
 ("gatech-grad","https://grad.gatech.edu/"),
 ("rice-grad","https://graduate.rice.edu/"),
 ("jhu-sfs","https://sfs.jhu.edu/"),
 ("ucla-grad","https://grad.ucla.edu/"),
 ("ucla-registrar","https://registrar.ucla.edu/"),
 ("berkeley-grad","https://grad.berkeley.edu/"),
 ("berkeley-reg","https://registrar.berkeley.edu/"),
 ("berkeley-students","https://students.berkeley.edu/"),
 ("ucsd-grad","https://grad.ucsd.edu/"),
 ("ucsd-students","https://students.ucsd.edu/"),
 ("northwestern-tuition","https://www.northwestern.edu/sfs/"),
 ("usnews-usc","https://www.usc.edu/admission-aid/tuition-and-costs/"),
 ("nyu-bursar","https://www.nyu.edu/students/student-information-and-resources/bills-payments-and-refunds/tuition-and-fees.html"),
 ("vanderbilt-tuition","https://www.vanderbilt.edu/studentaccounts/tuition-and-fees/"),
 ("dartmouth-tuition","https://www.dartmouth.edu/bursar/"),
 ("nd-tuition","https://controller.nd.edu/student-accounts-and-cashiering/tuition-and-fees/"),
 ("emory-tuition","https://www.emory.edu/students/tuition-fees/"),
 ("wustl-tuition","https://studentaccount.wustl.edu/tuition-and-fees/"),
 ("brown-tuition","https://www.brown.edu/about/administration/bursar/tuition-fees"),
]

def probe(item):
    name, u = item
    try:
        r = requests.get(u, headers=UA, timeout=12, verify=False, allow_redirects=True)
        cf = "CHALLENGE" if "Cf-Mitigated" in r.headers or "Just a moment" in r.text[:2000] else "ok"
        return f"{name:22s} {r.status_code} len={len(r.text):6d} {cf:9s} {u}"
    except Exception as e:
        return f"{name:22s} ERR {type(e).__name__:20s} {u}"

with cf.ThreadPoolExecutor(max_workers=8) as ex:
    for line in ex.map(probe, urls):
        print(line)
