feat: F3 — extracto de PDF en notificaciones y comando /pdf (pypdf, sin disco)

This commit is contained in:
markosbenitez
2026-05-30 01:13:31 -03:00
parent 64cfc4d1b7
commit 61a15c5c50
5 changed files with 113 additions and 3 deletions

View File

@@ -23,8 +23,10 @@ from csj_client import (
CSJAuthError,
CSJClient,
CSJConnectionError,
CSJDocumentoNoDisponibleError,
CSJPasswordTemporalError,
)
from pdf_extractor import extraer_extracto
from database import delete_tenant, get_tenant, list_active_tenants, save_tenant
from storage import Snapshot
@@ -66,6 +68,29 @@ class Poller:
self._snapshots[chat_id] = Snapshot(path)
return self._snapshots[chat_id]
async def _intentar_extracto(
self,
client: CSJClient,
notif: object,
) -> str | None:
"""Descarga el PDF de la notificación y extrae el texto. Degradación elegante: None si falla."""
from csj_client import NotificacionPendiente # evita import circular en type hint
assert isinstance(notif, NotificacionPendiente)
if not (notif.cod_caso_judicial and notif.cod_actuacion_caso and notif.origen is not None):
return None
try:
pdf_bytes = await client.descargar_documento_principal(
cod_caso_judicial=notif.cod_caso_judicial,
origen_caso=notif.origen,
cod_actuacion_caso=notif.cod_actuacion_caso,
origen_actuacion=notif.origen,
)
return extraer_extracto(pdf_bytes)
except (CSJDocumentoNoDisponibleError, CSJConnectionError, CSJAuthError):
return None
except Exception:
return None
# ──────────────────────────────────────────────────────────────────────────
# Lógica de revisión por tenant
# ──────────────────────────────────────────────────────────────────────────
@@ -117,7 +142,8 @@ class Poller:
if nuevas:
for notif in nuevas:
await self._bot.enviar_notificacion(notif, tenant) # type: ignore[attr-defined]
extracto = await self._intentar_extracto(client, notif)
await self._bot.enviar_notificacion(notif, tenant, extracto=extracto) # type: ignore[attr-defined]
snapshot.marcar_vista(notif.cod_notificacion_origen)
elif es_manual:
await self._bot.enviar_sin_novedades(tenant, snapshot) # type: ignore[attr-defined]