-
Notifications
You must be signed in to change notification settings - Fork 0
Fix scheduling issues on Zeabur by adding timezone support for Buenos Aires #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ec78f09
4cbbd0e
d482fa0
51ea9d0
22dcb28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -35,7 +35,7 @@ | |||||
| telegram_token, telegram_chat_id, estado_normal, url_estado_subte, | ||||||
| intervalo_ejecucion, umbral_obra_programada, dias_renotificar_obra, | ||||||
| archivo_estado, estado_redundante, dias_limpiar_historial, | ||||||
| horario_analisis_inicio, horario_analisis_fin | ||||||
| horario_analisis_inicio, horario_analisis_fin, timezone_local | ||||||
| ) | ||||||
|
|
||||||
|
|
||||||
|
|
@@ -70,7 +70,7 @@ def guardar_estados(estados_actuales, historial): | |||||
| """Guarda el estado actual y el historial en un archivo JSON""" | ||||||
| try: | ||||||
| data = { | ||||||
| "ultima_actualizacion": datetime.now().isoformat(), | ||||||
| "ultima_actualizacion": datetime.now(timezone_local).isoformat(), | ||||||
| "estados_actuales": estados_actuales, | ||||||
| "historial": historial | ||||||
| } | ||||||
|
|
@@ -182,7 +182,7 @@ def procesar_obra_individual(linea, obra, indice, historial): | |||||
| "linea_original": linea, | ||||||
| "tipo": "obra", | ||||||
| "contador": 1, | ||||||
| "primera_deteccion": datetime.now().isoformat(), | ||||||
| "primera_deteccion": datetime.now(timezone_local).isoformat(), | ||||||
| "ultima_notificacion": None, | ||||||
| "es_obra_programada": True, | ||||||
| "detectada_por_texto": True, | ||||||
|
|
@@ -197,15 +197,15 @@ def procesar_obra_individual(linea, obra, indice, historial): | |||||
|
|
||||||
| if not historial[clave_obra].get("activa", True): | ||||||
| historial[clave_obra]["activa"] = True | ||||||
| historial[clave_obra]["fecha_reactivacion"] = datetime.now().isoformat() | ||||||
| historial[clave_obra]["fecha_reactivacion"] = datetime.now(timezone_local).isoformat() | ||||||
| return "reactivada_silenciosa", obra | ||||||
|
|
||||||
| elif (historial[clave_obra]["es_obra_programada"] and | ||||||
| historial[clave_obra].get("ya_notificada", False)): | ||||||
| ultima_notif = historial[clave_obra]["ultima_notificacion"] | ||||||
| if ultima_notif: | ||||||
| ultima_fecha = datetime.fromisoformat(ultima_notif) | ||||||
| if datetime.now() - ultima_fecha >= timedelta(days=dias_renotificar_obra): | ||||||
| if datetime.now(timezone_local) - ultima_fecha >= timedelta(days=dias_renotificar_obra): | ||||||
| return "renotificar", obra | ||||||
|
Comment on lines
205
to
209
|
||||||
| return "continua", obra | ||||||
| else: | ||||||
|
|
@@ -215,7 +215,7 @@ def procesar_obra_individual(linea, obra, indice, historial): | |||||
| "linea_original": linea, | ||||||
| "tipo": "obra", | ||||||
| "contador": 1, | ||||||
| "primera_deteccion": datetime.now().isoformat(), | ||||||
| "primera_deteccion": datetime.now(timezone_local).isoformat(), | ||||||
| "ultima_notificacion": None, | ||||||
| "es_obra_programada": True, | ||||||
| "detectada_por_texto": True, | ||||||
|
|
@@ -234,7 +234,7 @@ def procesar_problema_individual(linea, problema, indice, historial): | |||||
| "linea_original": linea, | ||||||
| "tipo": "problema", | ||||||
| "contador": 1, | ||||||
| "primera_deteccion": datetime.now().isoformat(), | ||||||
| "primera_deteccion": datetime.now(timezone_local).isoformat(), | ||||||
| "ultima_notificacion": None, | ||||||
| "es_obra_programada": False, | ||||||
| "detectada_por_texto": False, | ||||||
|
|
@@ -248,7 +248,7 @@ def procesar_problema_individual(linea, problema, indice, historial): | |||||
|
|
||||||
| if not historial[clave_problema].get("activa", True): | ||||||
| historial[clave_problema]["activa"] = True | ||||||
| historial[clave_problema]["fecha_reactivacion"] = datetime.now().isoformat() | ||||||
| historial[clave_problema]["fecha_reactivacion"] = datetime.now(timezone_local).isoformat() | ||||||
| return "problema_reactivado", problema | ||||||
|
|
||||||
| if (historial[clave_problema]["contador"] >= umbral_obra_programada and | ||||||
|
|
@@ -267,7 +267,7 @@ def procesar_problema_individual(linea, problema, indice, historial): | |||||
| "linea_original": linea, | ||||||
| "tipo": "problema", | ||||||
| "contador": 1, | ||||||
| "primera_deteccion": datetime.now().isoformat(), | ||||||
| "primera_deteccion": datetime.now(timezone_local).isoformat(), | ||||||
| "ultima_notificacion": None, | ||||||
| "es_obra_programada": False, | ||||||
| "detectada_por_texto": False, | ||||||
|
|
@@ -303,7 +303,7 @@ def detectar_componentes_desaparecidos(linea, componentes, historial): | |||||
| del historial[clave] | ||||||
| else: | ||||||
| historial[clave]["activa"] = False | ||||||
| historial[clave]["fecha_desaparicion"] = datetime.now().isoformat() | ||||||
| historial[clave]["fecha_desaparicion"] = datetime.now(timezone_local).isoformat() | ||||||
|
|
||||||
| return cambios_resueltos | ||||||
|
|
||||||
|
|
@@ -366,7 +366,7 @@ def procesar_linea_normal(linea, historial): | |||||
|
|
||||||
| def actualizar_timestamps_notificacion(cambios_nuevos, obras_programadas, obras_renotificar, historial): | ||||||
| """Actualiza los timestamps de notificación""" | ||||||
| ahora = datetime.now().isoformat() | ||||||
| ahora = datetime.now(timezone_local).isoformat() | ||||||
|
|
||||||
| for linea_dict in [cambios_nuevos, obras_programadas, obras_renotificar]: | ||||||
| for linea in linea_dict.keys(): | ||||||
|
|
@@ -378,7 +378,7 @@ def limpiar_historial_antiguo(historial): | |||||
| """Elimina entradas inactivas después de X días, | ||||||
| incluyendo obras clasificadas por persistencia""" | ||||||
| claves_a_eliminar = [] | ||||||
| ahora = datetime.now() | ||||||
| ahora = datetime.now(timezone_local) | ||||||
|
|
||||||
| for clave, datos in historial.items(): | ||||||
| if not datos.get("activa", True): | ||||||
|
|
@@ -564,14 +564,15 @@ def enviar_mensaje_telegram(mensaje): | |||||
| def horarios_de_analisis(): | ||||||
| """Determino el horario de análisis | ||||||
| horario de 6 am - 23 pm (definido desde config.py) | ||||||
agmonetti marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| Usa timezone de Buenos Aires para evitar problemas con servidores UTC | ||||||
| """ | ||||||
| hora_actual = datetime.now().hour | ||||||
| hora_actual = datetime.now(timezone_local).hour | ||||||
|
||||||
| return (horario_analisis_inicio <= hora_actual <= horario_analisis_fin) | ||||||
|
|
||||||
| def verificar_estados(): | ||||||
| """Función principal que verifica los estados y envía alertas si es necesario""" | ||||||
agmonetti marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| try: | ||||||
| print(f"Iniciando verificación - {time.strftime('%Y-%m-%d %H:%M:%S')}") | ||||||
| print(f"Iniciando verificación - {datetime.now(timezone_local).strftime('%Y-%m-%d %H:%M:%S')}") | ||||||
agmonetti marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| estados = obtener_estado_subte() | ||||||
|
|
||||||
| if not estados: | ||||||
|
|
@@ -594,7 +595,7 @@ def verificar_estados(): | |||||
| def main(): | ||||||
| """Función principal que ejecuta el ciclo de verificación periódica""" | ||||||
| while True: | ||||||
| hora_actual = datetime.now().hour | ||||||
| hora_actual = datetime.now(timezone_local).hour | ||||||
|
||||||
| hora_actual = datetime.now(timezone_local).hour | |
| hora_actual = ahora_ba().hour |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no me gusta esa funcion "ahora_ba", la quiero fuera de mi codigo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usar la libreria "zoneinfo"? en lugar de agregar otra dependencia a requirents.txt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usar la libreria "zoneinfo"? en lugar de agregar otra dependencia a requirents.txt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mixing timezone-aware and naive datetimes can raise TypeError here if ultima_notificacion was stored previously without a timezone offset. Ensure ultima_fecha is timezone-aware (in timezone_local) before subtracting, e.g., localize when tzinfo is None.