03-ago: [videoclub] proyecto listado diario RealDebrid Torrentio (99 titulos) + notificacion IDD + descarga NAS Synology
This commit is contained in:
56
videoclub/tg_notify.py
Normal file
56
videoclub/tg_notify.py
Normal file
@@ -0,0 +1,56 @@
|
||||
"""
|
||||
tg_notify.py — Envia el resumen diario del videoclub SOLO al canal IDD de Telegram.
|
||||
|
||||
Reutiliza el mecanismo de idd_channel.py (bot API) para que los mensajes
|
||||
vayan exclusivamente al canal IDD (-1003967773087), nunca a otros sitios.
|
||||
"""
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
REPO_NEGOCIO = Path(r"C:\Users\juanm\Documents\GitHub\biblioteca_negocio_prolongo\scripts")
|
||||
|
||||
sys.path.insert(0, str(REPO_NEGOCIO))
|
||||
import idd_channel # noqa: E402
|
||||
|
||||
|
||||
def _formatear(fecha, items, novedades):
|
||||
g = {"pelicula": [], "serie": [], "adulto": [], "otro": []}
|
||||
for it in items:
|
||||
tipo = it["tipo"]
|
||||
g.setdefault(tipo, []).append(it)
|
||||
totales = {k: len(v) for k, v in g.items()}
|
||||
|
||||
lineas = [f"🎬 *Videoclub {fecha}*",
|
||||
f"Disponibles: {len(items)} · "
|
||||
f"Novedades: {len(novedades)}",
|
||||
""]
|
||||
if novedades:
|
||||
lineas.append(f"✨ *Novedades ({len(novedades)})*")
|
||||
lineas.append("")
|
||||
for it in novedades[:20]:
|
||||
marca = {"pelicula": "🎬", "serie": "📺", "adulto": "🔞", "otro": "📁"}.get(it["tipo"], "📁")
|
||||
y = f" ({it['year']})" if it["year"] else ""
|
||||
lineas.append(f"{marca} {it['clean']}{y}")
|
||||
if len(novedades) > 20:
|
||||
lineas.append(f"... y {len(novedades) - 20} más")
|
||||
return "\n".join(lineas)
|
||||
|
||||
|
||||
def enviar_novedades(fecha, items, novedades):
|
||||
texto = _formatear(fecha, items, novedades)
|
||||
# Limitar a 3500 caracteres (limite de Telegram)
|
||||
if len(texto) > 3500:
|
||||
texto = texto[:3450] + "\n…"
|
||||
return idd_channel.send_message(texto)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 2:
|
||||
print("Uso: python tg_notify.py 'texto'")
|
||||
sys.exit(1)
|
||||
texto = sys.argv[1]
|
||||
# Estructura mínima para reutilizar _formatear manualmente
|
||||
# (normalmente se llama desde videoclub.py con datos reales)
|
||||
r = idd_channel.send_message(texto)
|
||||
print(f"Enviado a IDD: {'OK' if r else 'fallo'}")
|
||||
Reference in New Issue
Block a user