Files
feadulta/scripts/homenajes-2026-06/mardones_build_manifest.py
rafa a2aefd8e0b scripts(homenajes): migración Mardones/Galarreta + sync prod #130/#131/#133/#137/#138
Pipeline de los 23 posts de Mardones (anterior/*.htm → posts), repunte de
presentaciones de Galarreta, y scripts de sync a prod de las 5 issues del día.
Incluye retoques de fecha (2012-10-10) y eliminación de target=_blank en el
homenaje 17990.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 09:06:39 -04:00

94 lines
4.4 KiB
Python

import re, json, html, glob
IMG_BASE = "/fea/wp-content/uploads/anterior-mardones/"
# filename -> (titulo, autor_wp, [imagenes])
ORAR_AUTHOR = 710 # Mardones
HOM_AUTHOR = 1 # genérico (como página 17990)
META = {
"orar-1-dejarmequerer":("Dejarme querer",ORAR_AUTHOR,[]),
"orar-2-escuchar":("Escuchar",ORAR_AUTHOR,[]),
"orar-3-estar":("Estar",ORAR_AUTHOR,[]),
"orar-4-hacersitioadios":("Hacer sitio a Dios",ORAR_AUTHOR,[]),
"orar-5-laoracionadulta":("La oración adulta",ORAR_AUTHOR,[]),
"orar-6-orarconevangelio":("Orar con el evangelio",ORAR_AUTHOR,[]),
"orar-7-orarrepitiendo":("Orar repitiendo una palabra o frase breve",ORAR_AUTHOR,[]),
"orar-8-tuestasdentro":("Tú estás dentro",ORAR_AUTHOR,[]),
"homenaje-segundo-aniversario":("En el segundo aniversario",HOM_AUTHOR,[]),
"homenaje-14noviembre":("14 de noviembre de 2007",HOM_AUTHOR,[]),
"homenaje-PRIMERaniversario":("Primer aniversario",HOM_AUTHOR,[]),
"homenaje-aniversario":("Programa en el aniversario",HOM_AUTHOR,["homenaje-charla-mejico.jpg"]),
"homenaje-rostrointerior":("Rostro interior de José María Mardones",HOM_AUTHOR,[]),
"homenaje-cartaReyes":("Carta a un Maestro",HOM_AUTHOR,[]),
"homenaje-9":("Semblanza",HOM_AUTHOR,[]),
"homenaje-8":("Álbum de fotos de José María Mardones",HOM_AUTHOR,
["homenaje-album-%d.jpg"%i for i in range(1,8)]),
"homenaje-1":("Funeral del sábado 24 de junio",HOM_AUTHOR,[]),
"homenaje-2":("Funeral del jueves 29 de junio",HOM_AUTHOR,[]),
"homenaje-5":("Obituario en El Mundo",HOM_AUTHOR,[]),
"homenaje-6":("Necrológicas en El País",HOM_AUTHOR,[]),
"homenaje-4":("Salmo a la Encarnación de Dios",HOM_AUTHOR,[]),
"homenaje-3":("Conferencia: ¿Por qué preocuparse por los demás? Ética y convivencia",HOM_AUTHOR,[]),
"homenaje-7":("Currículo de José María Mardones",HOM_AUTHOR,[]),
}
BOILER = re.compile(r'cristianos siglo veintiuno|^I N M E M O R I A M$|^HOMENAJE$|^homenaje a JOSE|APRENDIENDO A ORAR cristianos', re.I)
def extract(fn):
raw=open(fn,'rb').read().decode('windows-1252',errors='replace')
raw=re.sub(r'(?is)<(script|style).*?</\1>','',raw)
raw=re.sub(r'(?is)<!--.*?-->','',raw)
blocks=[]
for p in re.findall(r'(?is)<p\b[^>]*>(.*?)</p>',raw):
# preservar enlaces externos
links=re.findall(r'(?is)<a\s+[^>]*href="(https?://[^"]+)"[^>]*>(.*?)</a>',p)
t=re.sub(r'(?is)<[^>]+>','',p)
t=html.unescape(t).replace('\xa0',' ')
t=re.sub(r'\s+',' ',t).strip()
if len(t)<3:
# párrafo solo-enlace
if links:
for href,txt in links:
txt=re.sub(r'<[^>]+>','',txt).strip() or href
blocks.append(('link',href,txt))
continue
if BOILER.search(t):
continue
# ¿el párrafo contiene un enlace externo embebido? añadir como link extra
blocks.append(('p',t,links))
return blocks
def build_html(blocks, imgs):
out=[]
for b in blocks:
if b[0]=='p':
if re.match(r'^https?://\S+$', b[1]):
out.append('<p><a href="%s" target="_blank" rel="noopener">%s</a></p>'%(html.escape(b[1]),html.escape(b[1])))
continue
txt=html.escape(b[1])
# re-incrustar enlaces externos que estaban en el párrafo
for href,atxt in b[2]:
atxt_clean=html.escape(re.sub(r'<[^>]+>','',atxt).strip() or href)
# no siempre está el texto en txt; añadimos al final si no
out.append("<p>%s</p>"%txt)
elif b[0]=='link':
out.append('<p><a href="%s" target="_blank" rel="noopener">%s</a></p>'%(html.escape(b[1]),html.escape(b[2])))
# imágenes al final
for im in imgs:
out.append('<p><img src="%s%s" alt="José María Mardones" style="max-width:100%%;height:auto"/></p>'%(IMG_BASE,im))
return "\n".join(out)
manifest=[]
for fn in sorted(glob.glob("*.htm")):
key=fn[:-4]
if key not in META:
print("SIN META:",key); continue
title,author,imgs=META[key]
blocks=extract(fn)
content=build_html(blocks,imgs)
manifest.append({"file":key,"title":title,"author":author,"content":content,"nparas":len([b for b in blocks if b[0]=='p']),"nimgs":len(imgs)})
json.dump(manifest,open("manifest.json","w"),ensure_ascii=False,indent=1)
print("manifest:",len(manifest),"posts")
for m in manifest: print(f" {m['file']:34} '{m['title'][:35]}' autor={m['author']} paras={m['nparas']} imgs={m['nimgs']} len={len(m['content'])}")