diff --git a/config.sample.json b/config.sample.json index 7ed77f2..1c4fad8 100644 --- a/config.sample.json +++ b/config.sample.json @@ -3,5 +3,6 @@ "freemobile_apikey":"", "openweathermap_city":"Paris,FR", "openweathermap_apikey":"", - "openweathermap_language":"fr" -} \ No newline at end of file + "openweathermap_language":"fr", + "locale":"fr_FR.utf8" +} diff --git a/weather_to_freemobile.py b/weather_to_freemobile.py index 0750e62..adec764 100755 --- a/weather_to_freemobile.py +++ b/weather_to_freemobile.py @@ -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'])),