Files
IPSExtractor/bots/bot_descarga/main.py
T

59 lines
1.5 KiB
Python

"""CLI para el Bot de Descargas PDF."""
from __future__ import annotations
import argparse
import sys
from bot_descarga.audit.events import BotEvent
from bot_descarga.config.settings import DEFAULT_SETTINGS
from bot_descarga.core.download_service import DownloadService
def _print_event(event: BotEvent) -> None:
print(event.display_message(), flush=True)
def build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
description="Descarga facturas PDF desde Imaging y las organiza por NIT."
)
parser.add_argument(
"--excel",
required=True,
help="Ruta al archivo Excel (col A=radicado, col B=NIT)",
)
parser.add_argument(
"--carpeta",
required=True,
help="Carpeta destino de las descargas",
)
return parser
def main(argv: list[str] | None = None) -> int:
args = build_parser().parse_args(argv)
service = DownloadService(
ruta_excel=args.excel,
carpeta_descarga=args.carpeta,
settings=DEFAULT_SETTINGS,
event_callback=_print_event,
)
summary = service.run()
audit_path = getattr(service.bus.jsonl_logger, "path", None)
if audit_path:
print(f"Auditoría JSONL: {audit_path}", flush=True)
print(
f"Resumen: {summary.exitosos}/{summary.total} exitosos, "
f"{len(summary.fallidos)} fallidos",
flush=True,
)
return 0 if not summary.fallidos else 1
if __name__ == "__main__":
sys.exit(main())