Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Co-authored-by: agmonetti <179014840+agmonetti@users.noreply.github.com>
Co-authored-by: agmonetti <179014840+agmonetti@users.noreply.github.com>
Co-authored-by: agmonetti <179014840+agmonetti@users.noreply.github.com>
agmonetti
left a comment
There was a problem hiding this comment.
dont like the "ahora_ba" function. use "horarios_analisis" instead
config.py
Outdated
| horario_analisis_inicio = int(os.getenv('horario_analisis_inicio', 6)) | ||
| horario_analisis_fin = int(os.getenv('horario_analisis_fin', 23)) No newline at end of file | ||
| horario_analisis_fin = int(os.getenv('horario_analisis_fin', 23)) | ||
| # Timezone para Buenos Aires |
There was a problem hiding this comment.
dont like this comment, just remove it
agmonetti
left a comment
There was a problem hiding this comment.
no me guata la funcion llamada "ahora_ba" no crees una funcion para eso, solo utiliza el contenido de esa funcion donde se requiera, pero copy and pastealo
There was a problem hiding this comment.
Pull Request Overview
Adds explicit Buenos Aires timezone handling to fix scheduling logic on UTC servers (e.g., Zeabur), ensuring all datetime operations are timezone-aware and aligned with BA local time.
- Introduces timezone configuration (America/Argentina/Buenos_Aires) and helper ahora_ba()
- Replaces naive datetime usages with timezone-aware variants across scheduling, persistence, and logging
- Updates docs to clarify time semantics for configuration
Reviewed Changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| subte_alerta.py | Applies timezone-aware datetime usage in scheduling, persistence, and logging; adds ahora_ba() helper. |
| config.py | Adds pytz dependency and defines timezone_local for Buenos Aires. |
| README.md | Documents that monitoring hours are in Buenos Aires time and notes timezone handling. |
| README.EN.md | Same documentation updates in English. |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| 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 ahora_ba() - ultima_fecha >= timedelta(days=dias_renotificar_obra): | ||
| return "renotificar", obra |
There was a problem hiding this comment.
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.
| Usa timezone de Buenos Aires para evitar problemas con servidores UTC | ||
| """ | ||
| hora_actual = datetime.now().hour | ||
| hora_actual = datetime.now(timezone_local).hour |
There was a problem hiding this comment.
[nitpick] Use the new helper for consistency and a single source of time: replace with ahora_ba().hour. The same applies to other direct calls (e.g., lines 579 and 602) to reduce duplication and centralize timezone usage.
agmonetti
left a comment
There was a problem hiding this comment.
eso esta bien, la verdad no me paracr que es necesaria la funcion "ahora_ba", me gusto como remplazaste todo correctamente.
|
porque no usas zoneinfo, es una libreria de python? prueba esa idea y deja rodo listo para mergear con el main en caso de que quiera aprobar los cambios |
porque no usas zoneinfo, es una libreria de python? prueba esa idea y deja rodo listo para mergear con el main en caso de que quiera aprobar los cambios |
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 4 out of 5 changed files in this pull request and generated 4 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| 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 ahora_ba() - ultima_fecha >= timedelta(days=dias_renotificar_obra): | ||
| return "renotificar", obra |
There was a problem hiding this comment.
ultima_fecha parsed from historical data may be offset-naive (pre-change values saved without tz). Subtracting an aware datetime (ahora_ba()) from a naive datetime raises TypeError. Normalize parsed timestamps by assigning a timezone when tzinfo is None (e.g., assume UTC and convert to timezone_local) before subtracting. For example: 'ultima_fecha = ultima_fecha.replace(tzinfo=timezone.utc).astimezone(timezone_local)'. You may need 'from datetime import timezone' at the top of the file.
| """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 |
There was a problem hiding this comment.
[nitpick] Use ahora_ba() for consistency: 'hora_actual = ahora_ba().hour'.
| hora_actual = datetime.now(timezone_local).hour | |
| hora_actual = ahora_ba().hour |
There was a problem hiding this comment.
no me gusta esa funcion "ahora_ba", la quiero fuera de mi codigo
There was a problem hiding this comment.
Usar la libreria "zoneinfo"? en lugar de agregar otra dependencia a requirents.txt?
There was a problem hiding this comment.
Usar la libreria "zoneinfo"? en lugar de agregar otra dependencia a requirents.txt?
|
fijate los comentarios en el ultimo change. no me gusta esa funcion "ahora_ba", la quiero fuera de mi codigo incorporar la librwria zoneinfo de python en lugar de incorporar otra dependencia? |
Co-authored-by: agmonetti <179014840+agmonetti@users.noreply.github.com>
Switched to zoneinfo (Python's built-in timezone library). Removed pytz dependency from requirements.txt and updated config.py to use
Removed the |
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Problem
When deployed on Zeabur at 18:18 (6:18 PM), the bot would execute a few times and then stop working. The bot was configured to run from 6 AM to 11 PM (Buenos Aires time) with 1.5-hour intervals between executions.
Root Cause
The bot used
datetime.now().hourto determine the current hour, which returns the server's local time. On Zeabur, servers run in UTC timezone, while Buenos Aires is UTC-3. This caused a 3-hour offset in scheduling logic.Example of the problem:
This resulted in the bot having the wrong status 6 hours per day (3 AM-5 AM and 9 PM-11 PM Buenos Aires time):
Solution
Added comprehensive timezone support using Python's built-in
zoneinfolibrary to ensure all datetime operations use Buenos Aires time (America/Argentina/Buenos_Aires, UTC-3), regardless of the server's timezone.Changes Made
Using built-in
zoneinfo(config.py)zoneinfo.ZoneInfo(available in Python 3.9+)Configured Buenos Aires timezone (
config.py)Updated all datetime operations (
subte_alerta.py)datetime.now()calls withdatetime.now(timezone_local)horarios_de_analisis())Updated documentation (
README.md,README.EN.md)horario_analisis_inicioandhorario_analisis_finare in Buenos Aires timeKey Implementation
All timestamp operations use
datetime.now(timezone_local)directly for clarity and explicitness.Testing
✅ All Python files compile successfully
✅ Timezone correctly set to America/Argentina/Buenos_Aires (UTC-3)
✅ All datetime objects are timezone-aware (not naive)
✅ Scheduling logic verified for all 24 hours
✅ ISO format timestamps include timezone offset (
-03:00)✅ Comprehensive test suite validates all scenarios
✅ zoneinfo works identically to external timezone libraries
Impact
Benefits
Fixes #8
Original prompt
Fixes #8
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.