polybar-weather: discard first forecast if in less than two hours

This commit is contained in:
Vincent Bernat 2021-08-11 10:14:28 +02:00
parent 6749e99d06
commit 8fd82af49f

View file

@ -160,9 +160,14 @@ if __name__ == "__main__":
current_weather = get_weather(options.owm_api_key, *location, "weather") current_weather = get_weather(options.owm_api_key, *location, "weather")
if options.forecasts: if options.forecasts:
forecast_weather = get_weather( forecast_weather = get_weather(
options.owm_api_key, *location, "forecast", count=options.forecasts options.owm_api_key, *location, "forecast", count=options.forecasts+1
)["list"] )["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: else:
forecast_weather = [] forecast_weather = []
description = current_weather["weather"][0]["description"] description = current_weather["weather"][0]["description"]