From 0129d85f706c5bea101fdcbc746a356445074cb5 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Wed, 11 Aug 2021 08:32:28 +0200 Subject: [PATCH] polybar-weather: also log first forecast time --- bin/polybar-weather | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/bin/polybar-weather b/bin/polybar-weather index b7d66a2..126384b 100755 --- a/bin/polybar-weather +++ b/bin/polybar-weather @@ -158,16 +158,21 @@ if __name__ == "__main__": # Grab current weather and forecast current_weather = get_weather(options.owm_api_key, *location, "weather") - forecast_weather = get_weather( - options.owm_api_key, *location, "forecast", count=options.forecasts - ) + if options.forecasts: + forecast_weather = get_weather( + options.owm_api_key, *location, "forecast", count=options.forecasts + )["list"] + logger.info(f"first forecast: {forecast_weather[0]['dt_txt']} UTC") + else: + forecast_weather = [] description = current_weather["weather"][0]["description"] city = current_weather["name"] logger.info(f"current weather at {city}: {description}") # Format output - conditions = [format_weather(data) - for data in [current_weather] + forecast_weather["list"]] + conditions = [ + format_weather(data) for data in [current_weather] + forecast_weather + ] while len(conditions) >= 2: if conditions[-1] == conditions[-2]: conditions.pop()