Add date localisation using config.json
This commit is contained in:
@ -3,5 +3,6 @@
|
||||
"freemobile_apikey":"",
|
||||
"openweathermap_city":"Paris,FR",
|
||||
"openweathermap_apikey":"",
|
||||
"openweathermap_language":"fr"
|
||||
}
|
||||
"openweathermap_language":"fr",
|
||||
"locale":"fr_FR.utf8"
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
A simple script that sends the daily weather to a FreeMobile phone
|
||||
"""
|
||||
import json
|
||||
import locale
|
||||
import logging
|
||||
import os
|
||||
import pyowm
|
||||
@ -14,6 +15,11 @@ class WeatherToFreemobile():
|
||||
logging.info('Load configuration from {}'.format(config_file))
|
||||
with open(config_file) as configuration:
|
||||
self.config = json.load(configuration)
|
||||
logging.info('Setting locale')
|
||||
try:
|
||||
locale.setlocale(locale.LC_TIME, self.config['locale'])
|
||||
except locale.Error:
|
||||
logging.warning('Error setting locale {}'.format(self.config['locale']))
|
||||
|
||||
def send_sms_to_freemobile(self, message):
|
||||
"""
|
||||
@ -51,7 +57,7 @@ class WeatherToFreemobile():
|
||||
for weather in f:
|
||||
temp = weather.get_temperature(unit='celsius')
|
||||
return_message += '{} : {} (min {}ºC, max {}ºC, rain:{}mm)'.format(
|
||||
weather.get_reference_time('date').strftime('%x'),
|
||||
weather.get_reference_time('date').strftime('%A %d').title(),
|
||||
weather.get_detailed_status(),
|
||||
round(float(temp['min'])),
|
||||
round(float(temp['max'])),
|
||||
|
Reference in New Issue
Block a user