mirror of
https://github.com/vincentbernat/i3wm-configuration.git
synced 2025-06-21 01:25:42 +02:00
weather: compute temperature range over 24 hours
This commit is contained in:
parent
2b955436d6
commit
4f44050fe7
1 changed files with 21 additions and 7 deletions
28
bin/weather
28
bin/weather
|
@ -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-}}")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue