Add an option to configure the number of days to display
This commit is contained in:
@ -4,5 +4,6 @@
|
|||||||
"openweathermap_city":"Paris,FR",
|
"openweathermap_city":"Paris,FR",
|
||||||
"openweathermap_apikey":"",
|
"openweathermap_apikey":"",
|
||||||
"openweathermap_language":"fr",
|
"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']
|
city = self.config['openweathermap_city']
|
||||||
apikey = self.config['openweathermap_apikey']
|
apikey = self.config['openweathermap_apikey']
|
||||||
apilanguage = self.config['openweathermap_language']
|
apilanguage = self.config['openweathermap_language']
|
||||||
|
number_of_days = self.config['number_of_days']
|
||||||
|
|
||||||
logging.info('Opening OpenWeatherMap API')
|
logging.info('Opening OpenWeatherMap API')
|
||||||
owm = pyowm.OWM(apikey,language=apilanguage)
|
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()
|
f = fc.get_forecast()
|
||||||
return_message=""
|
return_message=[]
|
||||||
for weather in f:
|
for weather in f:
|
||||||
temp = weather.get_temperature(unit='celsius')
|
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_reference_time('date').strftime('%A %d').title(),
|
||||||
weather.get_detailed_status(),
|
weather.get_detailed_status(),
|
||||||
round(float(temp['min'])),
|
round(float(temp['min'])),
|
||||||
round(float(temp['max'])),
|
round(float(temp['max'])),
|
||||||
weather.get_rain().get('all',0)
|
weather.get_rain().get('all',0)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
logging.info("Got the following weather: {}".format(return_message))
|
logging.info("Got the following weather: {}".format(return_message))
|
||||||
return return_message
|
return "\n".join(return_message)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
logging.basicConfig(level=logging.WARNING, format=' %(asctime)s - %(levelname)s - %(message)s')
|
logging.basicConfig(level=logging.WARNING, format=' %(asctime)s - %(levelname)s - %(message)s')
|
||||||
|
Reference in New Issue
Block a user