Add an option to configure the number of days to display

master
djib 4 years ago
parent 4dd9bd5809
commit 9558df0887
  1. 3
      config.sample.json
  2. 19
      weather_to_freemobile.py

@ -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
}

@ -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')

Loading…
Cancel
Save