diff --git a/main.py b/main.py index 0709fcf..b2f4616 100644 --- a/main.py +++ b/main.py @@ -19,6 +19,9 @@ HORARIOS = [ (17, 30, 21, 30, 1800, "full"), # 17:30 - 21:30 -> cada 30 minutos ] +# 0=lun, 1=mar, 2=mié, 3=jue, 4=vie, 5=sáb, 6=dom +DIAS_ACTIVOS = [0, 1, 2, 3, 4] # lun, mar, mie, jue, vie + # ============================================================================ def obtener_intervalo(dt: datetime) -> tuple[int, str] | None: minutos = dt.hour * 60 + dt.minute @@ -41,6 +44,15 @@ def segundos_hasta_proximo_inicio(dt: datetime) -> int: return int((inicio - dt).total_seconds()) +# ============================================================================ +def segundos_hasta_proximo_dia_activo(dt: datetime) -> int: + for dias in range(1, 8): + prox = dt + timedelta(days=dias) + if prox.weekday() in DIAS_ACTIVOS: + target = prox.replace(hour=6, minute=30, second=0, microsecond=0) + return int((target - dt).total_seconds()) + return 86400 + # ============================================================================ def cargar_empresas(): with open("empresas.json", "r", encoding="utf-8") as f: @@ -265,6 +277,19 @@ def main(): inicio_ciclo = datetime.now() + logger_utilities.rotar_log() + + if inicio_ciclo.weekday() not in DIAS_ACTIVOS: + dormir = segundos_hasta_proximo_dia_activo(inicio_ciclo) + print( + f"\n[{inicio_ciclo:%Y-%m-%d %H:%M:%S}] " + f"Día no activo (weekday={inicio_ciclo.weekday()}).\n" + f"Próxima ejecución: " + f"{(inicio_ciclo + timedelta(seconds=dormir)):%Y-%m-%d %H:%M:%S}" + ) + time.sleep(dormir) + continue + resultado = obtener_intervalo(inicio_ciclo) if resultado is not None: diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..6b45119 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,14 @@ +[project] +name = "validador_documentos" +version = "1.1.0" +description = "Validador de comprobantes electrónicos contra SUNAT" +requires-python = ">=3.10" +dependencies = [ + "certifi==2026.6.17", + "charset-normalizer==3.4.9", + "hdbcli==2.29.23", + "idna==3.18", + "python-dotenv==1.2.2", + "requests==2.34.2", + "urllib3==2.7.0", +]