Add date localisation using config.json
This commit is contained in:
@ -3,5 +3,6 @@
|
|||||||
"freemobile_apikey":"",
|
"freemobile_apikey":"",
|
||||||
"openweathermap_city":"Paris,FR",
|
"openweathermap_city":"Paris,FR",
|
||||||
"openweathermap_apikey":"",
|
"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
|
A simple script that sends the daily weather to a FreeMobile phone
|
||||||
"""
|
"""
|
||||||
import json
|
import json
|
||||||
|
import locale
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import pyowm
|
import pyowm
|
||||||
@ -14,6 +15,11 @@ class WeatherToFreemobile():
|
|||||||
logging.info('Load configuration from {}'.format(config_file))
|
logging.info('Load configuration from {}'.format(config_file))
|
||||||
with open(config_file) as configuration:
|
with open(config_file) as configuration:
|
||||||
self.config = json.load(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):
|
def send_sms_to_freemobile(self, message):
|
||||||
"""
|
"""
|
||||||
@ -51,7 +57,7 @@ class WeatherToFreemobile():
|
|||||||
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 += '{} : {} (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(),
|
weather.get_detailed_status(),
|
||||||
round(float(temp['min'])),
|
round(float(temp['min'])),
|
||||||
round(float(temp['max'])),
|
round(float(temp['max'])),
|
||||||
|
Reference in New Issue
Block a user