Created
May 5, 2025 20:55
-
-
Save AgustinParmisano/d7a483f2e70716a564bde0ec83bb48ea to your computer and use it in GitHub Desktop.
Primer etapa de alertador de condiciones meteorológicas adversas para la plata con consultas a api de meteo blue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import smtplib | |
from datetime import datetime | |
import locale | |
locale.setlocale(locale.LC_TIME, 'es_ES.UTF-8') # Linux | |
# locale.setlocale(locale.LC_TIME, 'Spanish_Spain.1252') # Windows | |
# Configuración | |
API_KEY = "NOPE" | |
LAT = -34.920345 # Latitud de La Plata | |
LON = -57.969559 # Longitud de La Plata | |
UMBRAL_PROB = 70 # Probabilidad mínima (%) | |
UMBRAL_MM = 0.2 # Precipitación mínima (mm) | |
# Obtener datos | |
url = f"https://my.meteoblue.com/packages/basic-1h?lat={LAT}&lon={LON}&apikey={API_KEY}&format=json" | |
response = requests.get(url) | |
data = response.json() | |
# Procesar datos | |
horas = data['data_1h']['time'] | |
probs = data['data_1h']['precipitation_probability'] | |
mms = data['data_1h']['precipitation'] | |
alertas = [] | |
for i in range(len(horas)): | |
prob = probs[i] | |
mm = mms[i] | |
if prob >= UMBRAL_PROB and mm >= UMBRAL_MM: | |
fecha_hora = datetime.fromisoformat(horas[i]) | |
alertas.append({ | |
"dia": fecha_hora.strftime("%A"), # Nombre del día | |
"fecha": fecha_hora.strftime("%d-%m-%Y"), # Fecha en formato dd-mm-YYYY | |
"hora": fecha_hora.strftime("%H:%M"), | |
"probabilidad": prob, | |
"mm": mm | |
}) | |
# Mostrar resultados | |
if alertas: | |
print("\n--- ALERTAS CUMPLEN AMBAS CONDICIONES ---") | |
print("Día Fecha Hora Prob (%) Precip (mm)") | |
print("-------------------------------------------------------") | |
for alerta in alertas: | |
print(f"{alerta['dia']:<10} {alerta['fecha']} {alerta['hora']} {alerta['probabilidad']:>3}% {alerta['mm']:>5.1f}") | |
else: | |
print("No hay alertas que cumplan ambos umbrales.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment