From 8fd82af49f15c91dc49643f13938909fe415c6b1 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Wed, 11 Aug 2021 10:14:28 +0200 Subject: [PATCH] polybar-weather: discard first forecast if in less than two hours --- bin/polybar-weather | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bin/polybar-weather b/bin/polybar-weather index 126384b..5cd2a64 100755 --- a/bin/polybar-weather +++ b/bin/polybar-weather @@ -160,9 +160,14 @@ if __name__ == "__main__": current_weather = get_weather(options.owm_api_key, *location, "weather") if options.forecasts: forecast_weather = get_weather( - options.owm_api_key, *location, "forecast", count=options.forecasts + options.owm_api_key, *location, "forecast", count=options.forecasts+1 )["list"] - logger.info(f"first forecast: {forecast_weather[0]['dt_txt']} UTC") + if forecast_weather[0]['dt'] - time.time() < 7200: + logger.debug("discard first forecast, too soon") + forecast_weather = forecast_weather[1:] + else: + forecast_weather.pop() + logger.info(f"next forecast: {forecast_weather[0]['dt_txt']} UTC") else: forecast_weather = [] description = current_weather["weather"][0]["description"]