#!/usr/bin/env python3 """Afina el cruce con Wayback: solo las URLs /es/ (el Joomla legacy), que es lo que el mirror cubre. El 52 % global del script anterior mezcla peras con manzanas: Wayback conoce feadulta.com desde antes de que existiera el Joomla (ficheros .htm sueltos en la raiz, que hoy viven bajo /anterior/) y tambien el WordPress actual (/wp-content, /wp-json). Nada de eso forma parte del mirror del legacy. """ import os, json, re 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 = set() 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 s = urlsplit(u) if s.query: continue if s.path.startswith("/es/"): paths.add(s.path) ok, missing = 0, [] for p in sorted(paths): if existe(p): ok += 1 else: missing.append(p) print("URLs /es/ conocidas por Wayback:", len(paths)) print("resuelven en el mirror:", ok, "(%.1f%%)" % (ok * 100.0 / max(len(paths), 1))) print("no resuelven:", len(missing)) tipo = Counter() for p in missing: seg = p.split("/") tipo["/".join(seg[:3])] += 1 print("\n--- las que faltan, por seccion ---") for k, v in tipo.most_common(15): print("%7d %s" % (v, k)) json.dump({"wayback_es_paths": len(paths), "presentes": ok, "ausentes": len(missing), "pct": round(ok * 100.0 / max(len(paths), 1), 2)}, open(os.path.join(DIR, "wayback-es-report.json"), "w"), indent=2) with open(os.path.join(DIR, "wayback-es-missing.txt"), "w") as f: for p in missing: f.write(p + "\n") print("\n--- muestra ---") for p in missing[:15]: print(" ", p)