weather: compute temperature range over 24 hours

This commit is contained in:
Vincent Bernat 2024-05-13 08:17:48 +02:00
parent 2b955436d6
commit 4f44050fe7

View file

@ -158,17 +158,31 @@ if __name__ == "__main__":
# Grab current weather and daily forecast
weather = get_weather(*location)
weather = weather["properties"]["timeseries"][0]["data"]
weather = weather["properties"]["timeseries"]
# Compute min/max temperatures for the forecast. We use the next 24
# hours. So we use 18 entries.
mintemp = min(
d["data"]["next_6_hours"]["details"]["air_temperature_min"]
for d in weather[:18]
)
maxtemp = max(
d["data"]["next_6_hours"]["details"]["air_temperature_max"]
for d in weather[:18]
)
# Format output
conditions = [
format_icon(weather["next_1_hours"]["summary"]["symbol_code"]),
"{}°C".format(round(weather["instant"]["details"]["air_temperature"])),
format_icon(weather["next_6_hours"]["summary"]["symbol_code"]),
"{}—{}°C".format(
round(weather["next_6_hours"]["details"]["air_temperature_min"]),
round(weather["next_6_hours"]["details"]["air_temperature_max"]),
# Current conditions: use the symbol for the next hour and the
# instant temperature
format_icon(weather[0]["data"]["next_1_hours"]["summary"]["symbol_code"]),
"{}°C".format(
round(weather[0]["data"]["instant"]["details"]["air_temperature"])
),
# Forecast: use the symbol for the next 6 hours
format_icon(weather[0]["data"]["next_6_hours"]["summary"]["symbol_code"]),
# And the temperature range computed for the next 24 hours
"{}—{}°C".format(round(mintemp), round(maxtemp)),
]
city = city.replace("%", "%%")
conditions.insert(0, f"%{{F#888}}{city}%{{F-}}")