mirror of
https://github.com/vincentbernat/i3wm-configuration.git
synced 2025-06-23 02:08:35 +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
|
# Grab current weather and daily forecast
|
||||||
weather = get_weather(*location)
|
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
|
# Format output
|
||||||
conditions = [
|
conditions = [
|
||||||
format_icon(weather["next_1_hours"]["summary"]["symbol_code"]),
|
# Current conditions: use the symbol for the next hour and the
|
||||||
"{}°C".format(round(weather["instant"]["details"]["air_temperature"])),
|
# instant temperature
|
||||||
format_icon(weather["next_6_hours"]["summary"]["symbol_code"]),
|
format_icon(weather[0]["data"]["next_1_hours"]["summary"]["symbol_code"]),
|
||||||
"{}—{}°C".format(
|
"{}°C".format(
|
||||||
round(weather["next_6_hours"]["details"]["air_temperature_min"]),
|
round(weather[0]["data"]["instant"]["details"]["air_temperature"])
|
||||||
round(weather["next_6_hours"]["details"]["air_temperature_max"]),
|
|
||||||
),
|
),
|
||||||
|
# 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("%", "%%")
|
city = city.replace("%", "%%")
|
||||||
conditions.insert(0, f"%{{F#888}}{city}%{{F-}}")
|
conditions.insert(0, f"%{{F#888}}{city}%{{F-}}")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue