se agrega programación de ejecución por día de semana, para que el servicio sea instalado por nssm

This commit is contained in:
George committed 2026-07-13 14:35:00 -05:00
1 parent 3ec141c752
commit fb54dbb281
2 files changed
+39

No files matched your search

+25
View File
@@ -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: