#!/usr/bin/env python3 """Antes de tocar nada: que hay realmente dentro de los bloques sociales del mirror.""" import os, re from collections import Counter BASE = "/home/rafa/joomla-migration/mirror-antiguo" RUN = open(os.path.join(BASE, "CURRENT_RUN")).read().strip() SITE = os.path.join(BASE, "runs", RUN, "site", "antiguo.feadulta.com") OPEN = re.compile(r']*class="[^"]*itemSocialSharing[^"]*"[^>]*>', re.I) DIV = re.compile(r']*>|', re.I) CLASS = re.compile(r']*class="([^"]+)"', re.I) SCRIPTSRC = re.compile(r']+src="([^"]+)"', re.I) def bloque(html, m): """Devuelve (inicio, fin) del div equilibrado que empieza en m.""" depth, pos = 0, m.start() for d in DIV.finditer(html, m.start()): if d.group(0).lower().startswith(" 400: break for m in OPEN.finditer(html): r = bloque(html, m) if not r: sin_bloque += 1 continue con_bloque += 1 frag = html[r[0]:r[1]] for c in CLASS.findall(frag): clases[c.strip()] += 1 for s in SCRIPTSRC.findall(frag): scripts[s.split("?")[0]] += 1 if n > 400: break print("paginas inspeccionadas con itemSocialSharing:", n) print("bloques equilibrados:", con_bloque, " sin cerrar:", sin_bloque) print("\n--- clases de div dentro del bloque ---") for k, v in clases.most_common(15): print("%7d %s" % (v, k)) print("\n--- scripts dentro del bloque ---") for k, v in scripts.most_common(15): print("%7d %s" % (v, k))