← back to Ga Allsites
_final_audit.py
43 lines
import json
import pathlib
import re
import ssl
import urllib.request
from concurrent.futures import ThreadPoolExecutor
cand=json.loads(pathlib.Path("cache/_candidates_noconf.json").read_text())
ctx=ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE
PARK=re.compile(r"(domain (is )?for sale|buy this domain|parked|godaddy|afternic|sedoparking|hugedomains|dan\.com|coming soon|under construction|default web page|welcome to nginx|apache2 ubuntu|it works!|future home)",re.IGNORECASE)
REAL=re.compile(r"(<nav|<article|add to cart|shop|our services|©\s*20|privacy policy|contact us|sign in|log ?in|<form)",re.IGNORECASE)
def dslug(d): return "".join(c for c in d.rsplit(".",1)[0].lower() if c.isalnum())
def probe(d):
for scheme in ("https","http"):
try:
req=urllib.request.Request(f"{scheme}://{d}/",headers={"User-Agent":"Mozilla/5.0"})
r=urllib.request.urlopen(req,timeout=10,context=ctx)
final=r.geturl(); html=r.read(120000).decode("utf-8","ignore"); code=r.getcode()
off = dslug(d) not in dslug(final.split("//")[-1].split("/")[0])
if off: return (d,"REDIRECT_OFF",final[:50])
if PARK.search(html) or len(html)<500: return (d,"EMPTY_PARKED",f"{code} {len(html)}b")
if REAL.search(html): return (d,"HAS_SITE",f"{code} {len(html)}b")
return (d,"THIN",f"{code} {len(html)}b")
except Exception as e:
if scheme=="http": return (d,"DEAD",str(e)[:30])
return (d,"DEAD","")
with ThreadPoolExecutor(max_workers=24) as ex:
res=list(ex.map(probe,cand))
from collections import defaultdict
b=defaultdict(list)
for d,c,info in res: b[c].append(d)
print("=== final audit of 87 no-Kamatera-conf candidates ===")
for k in ["EMPTY_PARKED","DEAD","THIN","REDIRECT_OFF","HAS_SITE"]:
print(f" {k:14} {len(b.get(k,[]))}")
# SAFE to build = genuinely empty (parked/dead). THIN = borderline (manual). Others = leave alone.
safe=sorted(b.get("EMPTY_PARKED",[])+b.get("DEAD",[]))
pathlib.Path("cache/_safe_to_build.json").write_text(json.dumps(safe))
pathlib.Path("cache/_thin_review.json").write_text(json.dumps(sorted(b.get("THIN",[]))))
print(f"\n>>> SAFE TO BUILD (genuinely empty): {len(safe)}")
print(f">>> THIN / needs eyeball: {len(b.get('THIN',[]))}")
print(f">>> leave alone (has site / redirects): {len(b.get('HAS_SITE',[]))+len(b.get('REDIRECT_OFF',[]))}")