This script uses the openmeteo_py library to retrieve meteorological data for the specified latitude and longitude (Thodupuzha, Idukki). The Hourly and Daily classes are used to specify the type of data to be retrieved (hourly or daily). The Options class is used to specify the location by latitude and longitude. The OWmanager class is used to manage data retrieval using the specified options and types of data.
The script then retrieves the meteorological data using mgr.get_data() and stores it in the meteo variable. The data for the next 5 days is then extracted from the meteo dictionary and stored in the five_days_forecast variable.
For each day in the five_days_forecast, the date, weather code, maximum and minimum temperatures, precipitation sum and hours, wind speed and gusts, wind direction, sunrise and sunset times, and shortwave radiation sum are extracted from the meteo dictionary. The weather code is then used to determine the summary of the weather conditions for that day.
Finally, the extracted data is printed out with descriptive labels. If the data is not available, the script will print an error message “Error: Data not available”.
from openmeteo_py import Hourly,Daily,Options,OWmanager
# Latitude, Longitude for Thodupuzha, Idukki
latitude = 9.917773198864504
longitude = 76.74575669934728
hourly = Hourly()
daily = Daily()
options = Options(latitude,longitude)
mgr = OWmanager(options, hourly.all(),daily.all())
# Download data
meteo = mgr.get_data()
#print(meteo)
try:
five_days_forecast = meteo['daily']['time'][:5]
for day in five_days_forecast:
date = day
weather_code = meteo['daily']['weathercode'][five_days_forecast.index(day)]
temperature_max = meteo['daily']['apparent_temperature_max'][five_days_forecast.index(day)]
temperature_min = meteo['daily']['apparent_temperature_min'][five_days_forecast.index(day)]
precipitation_sum = meteo['daily']['precipitation_sum'][five_days_forecast.index(day)]
precipitation_hours = meteo['daily']['precipitation_hours'][five_days_forecast.index(day)]
windspeed_10m_max = meteo['daily']['windspeed_10m_max'][five_days_forecast.index(day)]
windgusts_10m_max = meteo['daily']['windgusts_10m_max'][five_days_forecast.index(day)]
winddirection_10m_dominant = meteo['daily']['winddirection_10m_dominant'][five_days_forecast.index(day)]
sunrise = meteo['daily']['sunrise'][five_days_forecast.index(day)]
sunset = meteo['daily']['sunset'][five_days_forecast.index(day)]
shortwave_radiation_sum = meteo['daily']['shortwave_radiation_sum'][five_days_forecast.index(day)]
if weather_code == 0:
summary = "Clear sky"
elif weather_code in [1, 2, 3]:
summary = "Mainly clear, partly cloudy, and overcast"
elif weather_code in [45, 48]:
summary = "Fog and depositing rime fog"
elif weather_code in [51, 53, 55]:
summary = "Drizzle: Light, moderate, and dense intensity"
elif weather_code in [56, 57]:
summary = "Freezing Drizzle: Light and dense intensity"
elif weather_code in [61, 63, 65]:
summary = "Rain: Slight, moderate and heavy intensity"
elif weather_code in [66, 67]:
summary = "Freezing Rain: Light and heavy intensity"
elif weather_code in [71, 73, 75]:
summary = "Snow fall: Slight, moderate, and heavy intensity"
elif weather_code == 77:
summary = "Snow grains"
elif weather_code in [80, 81, 82]:
summary = "Rain showers: Slight, moderate, and violent"
elif weather_code in [85, 86]:
summary = "Snow showers slight and heavy"
elif weather_code in [95, 96, 99]:
summary = "Thunderstorm: Slight or moderate with slight and heavy"
print("Date: ", date)
print("Summary: ", summary)
print("Temperature (Max): ", temperature_max, "°C")
print("Temperature (Min): ", temperature_min, "°C")
print("Precipitation Sum: ", precipitation_sum, "mm")
print("Precipitation Hours: ", precipitation_hours, "h")
print("Wind Speed (Max): ", windspeed_10m_max, "km/h")
print("Wind Gusts (Max): ", windgusts_10m_max, "km/h")
print("Wind Direction: ", winddirection_10m_dominant, "°")
print("Sunrise: ", sunrise)
print("Sunset: ", sunset)
print("Shortwave Radiation Sum: ", shortwave_radiation_sum, "MJ/m²")
print("\n")
except KeyError:
print("Error: Data not available")
Output Sample:-
Date: 2023-02-12
Summary: Mainly clear, partly cloudy, and overcast
Temperature (Max): 37.7 °C
Temperature (Min): 18.8 °C
Precipitation Sum: 0.0 mm
Precipitation Hours: 0.0 h
Wind Speed (Max): 10.9 km/h
Wind Gusts (Max): 26.3 km/h
Wind Direction: 288 °
Sunrise: 2023-02-12T01:12
Sunset: 2023-02-12T13:02
Shortwave Radiation Sum: 24.54 MJ/m²










