From 9558df08874a7e84261f72b112ef822762711d7d Mon Sep 17 00:00:00 2001 From: djib Date: Sun, 22 Sep 2019 08:28:00 +0200 Subject: [PATCH] Add an option to configure the number of days to display --- config.sample.json | 3 ++- weather_to_freemobile.py | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/config.sample.json b/config.sample.json index 1c4fad8..f0677ad 100644 --- a/config.sample.json +++ b/config.sample.json @@ -4,5 +4,6 @@ "openweathermap_city":"Paris,FR", "openweathermap_apikey":"", "openweathermap_language":"fr", - "locale":"fr_FR.utf8" + "locale":"fr_FR.utf8", + "number_of_days":2 } diff --git a/weather_to_freemobile.py b/weather_to_freemobile.py index 4a56b9a..d28fa08 100755 --- a/weather_to_freemobile.py +++ b/weather_to_freemobile.py @@ -47,24 +47,27 @@ class WeatherToFreemobile(): city = self.config['openweathermap_city'] apikey = self.config['openweathermap_apikey'] apilanguage = self.config['openweathermap_language'] + number_of_days = self.config['number_of_days'] logging.info('Opening OpenWeatherMap API') owm = pyowm.OWM(apikey,language=apilanguage) - fc = owm.daily_forecast(city,limit=1) + fc = owm.daily_forecast(city,limit=number_of_days) f = fc.get_forecast() - return_message="" + return_message=[] for weather in f: temp = weather.get_temperature(unit='celsius') - return_message += '{} : {} (min {}ºC, max {}ºC, rain:{}mm)'.format( + return_message.append( + '{} : {} (min {}ºC, max {}ºC, rain:{}mm)'.format( weather.get_reference_time('date').strftime('%A %d').title(), - weather.get_detailed_status(), - round(float(temp['min'])), - round(float(temp['max'])), - weather.get_rain().get('all',0) + weather.get_detailed_status(), + round(float(temp['min'])), + round(float(temp['max'])), + weather.get_rain().get('all',0) + ) ) logging.info("Got the following weather: {}".format(return_message)) - return return_message + return "\n".join(return_message) if __name__ == "__main__": logging.basicConfig(level=logging.WARNING, format=' %(asctime)s - %(levelname)s - %(message)s')