#!/usr/bin/env python3 """Cruza el inventario historico de Internet Archive contra el mirror. Responde a la pregunta de aceptacion que de verdad importa: **de las URLs legacy que el mundo exterior tiene enlazadas, cuantas resuelven en el mirror**. Sustituto parcial de la fuente F2 (GA4), que sigue bloqueada porque requiere que Rafa abra el OAuth a mano. """ import os, json from collections import Counter from urllib.parse import urlsplit, unquote BASE = "/home/rafa/joomla-migration/mirror-antiguo" RUN = open(os.path.join(BASE, "CURRENT_RUN")).read().strip() DIR = os.path.join(BASE, "runs", RUN) SITE = os.path.join(DIR, "site", "antiguo.feadulta.com") def existe(path): p = unquote(path).lstrip("/") for c in (p, p.split("?", 1)[0], os.path.join(p, "index.html")): if c and os.path.isfile(os.path.join(SITE, c)): return True return False paths, cats = set(), Counter() for fn in ("wayback-antiguo.txt", "wayback-feadulta.txt"): for line in open(os.path.join(BASE, "inventory", fn), errors="replace"): u = line.strip() if not u: continue p = urlsplit(u).path q = urlsplit(u).query if q: # las URLs con query no forman parte del mirror estatico cats["con_query (fuera de alcance)"] += 1 continue if not p or p == "/": cats["raiz"] += 1 continue paths.add(p) ok, missing = 0, [] for p in sorted(paths): if existe(p): ok += 1 else: missing.append(p) print("URLs distintas de Wayback sin query:", len(paths)) print("presentes en el mirror:", ok, "(%.1f%%)" % (ok * 100.0 / max(len(paths), 1))) print("ausentes:", len(missing)) for k, v in cats.most_common(): print(" %s: %s" % (k, v)) # clasificar las ausentes para ver si importan tipo = Counter() for p in missing: seg = p.strip("/").split("/")[0] if p.strip("/") else "(raiz)" tipo[seg] += 1 print("\n--- ausentes por primer segmento ---") for k, v in tipo.most_common(20): print("%7d %s" % (v, k)) with open(os.path.join(DIR, "wayback-missing.txt"), "w") as f: for p in missing: f.write(p + "\n") json.dump({"wayback_paths": len(paths), "presentes": ok, "ausentes": len(missing), "pct": round(ok * 100.0 / max(len(paths), 1), 2)}, open(os.path.join(DIR, "wayback-report.json"), "w"), indent=2) print("\n--- muestra de ausentes ---") for p in missing[:20]: print(" ", p)