Files
progcode/deploy/check-outbound-http.py
T

8 lines
1.1 KiB
Python

from pathlib import Path
import json,subprocess,hashlib,concurrent.futures
r=Path(__file__).resolve().parents[1];d=r/'docs/rebuild-v2';urls=json.load(open(d/'outbound-check-queue.json'));out=d/'raw/outbound';out.mkdir(exist_ok=True)
def check(u):
n=hashlib.sha256(u.encode()).hexdigest()[:16];p=out/(n+'.txt');q=subprocess.run(['curl','-sSL','--max-time','18','--max-filesize','3000000','-o',str(p),'-w','%{http_code}\n%{url_effective}',u],text=True,capture_output=True);lines=q.stdout.splitlines();b=p.read_bytes() if p.exists() else b'';x={'url':u,'httpStatus':int(lines[0]) if lines and lines[0].isdigit() else None,'resolvedURL':lines[-1] if lines else None,'transportExit':q.returncode,'transportError':q.stderr,'raw':str(p.relative_to(r)) if p.exists() else None,'sha256':hashlib.sha256(b).hexdigest() if b else None,'bodyBytes':len(b)};print(x['httpStatus'],u,x['transportExit'],flush=True);return x
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as pool:results=list(pool.map(check,urls))
(d/'outbound-http-results.json').write_text(json.dumps(results,ensure_ascii=False,indent=2)+'\n')