From 8e09731c13ada58ee492ee6c57464bc36fcaead3 Mon Sep 17 00:00:00 2001 From: Ace Date: Fri, 19 Jun 2020 19:40:50 +0200 Subject: [PATCH] Use common config instead of hardcoded config units, hour_format and language will be automatically set for each module --- inkycal/modules/inkycal_agenda.py | 8 +++++++- inkycal/modules/inkycal_calendar.py | 6 +++--- inkycal/modules/inkycal_weather.py | 10 +++++----- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/inkycal/modules/inkycal_agenda.py b/inkycal/modules/inkycal_agenda.py index 1ea9187..0c6aa3a 100644 --- a/inkycal/modules/inkycal_agenda.py +++ b/inkycal/modules/inkycal_agenda.py @@ -38,7 +38,7 @@ class Agenda(inkycal_module): # module specific parameters self.date_format = 'ddd D MMM' self.time_format = "HH:mm" - self.language = 'en' + self.language = self.config['language'] self.timezone = get_system_tz() self.ical_urls = self.config['ical_urls'] self.ical_files = [] @@ -48,16 +48,22 @@ class Agenda(inkycal_module): def _validate(self): """Validate module-specific parameters""" + if not isinstance(self.date_format, str): print('date_format has to be an arrow-compatible token') + if not isinstance(self.time_format, str): print('time_format has to be an arrow-compatible token') + if not isinstance(self.language, str): print('language has to be a string: "en" ') + if not isinstance(self.timezone, str): print('The timezone has bo be a string.') + if not isinstance(self.ical_urls, list): print('ical_urls has to be a list ["url1", "url2"] ') + if not isinstance(self.ical_files, list): print('ical_files has to be a list ["path1", "path2"] ') diff --git a/inkycal/modules/inkycal_calendar.py b/inkycal/modules/inkycal_calendar.py index f75fef5..1a20851 100644 --- a/inkycal/modules/inkycal_calendar.py +++ b/inkycal/modules/inkycal_calendar.py @@ -40,7 +40,7 @@ class Calendar(inkycal_module): self.show_events = True self.date_format = 'D MMM' self.time_format = "HH:mm" - self.language = 'en' + self.language = self.config['language'] self.timezone = get_system_tz() self.ical_urls = self.config['ical_urls'] @@ -261,8 +261,8 @@ class Calendar(inkycal_module): (event_width_l, line_height), name, font=self.font, alignment = 'left') else: - write(im_black, (time_width, event_lines[cursor][1]), - (event_width_s, line_height), time, font=self.font, + write(im_black, (date_width, event_lines[cursor][1]), + (time_width, line_height), time, font=self.font, alignment = 'left') write(im_black, (date_width+time_width,event_lines[cursor][1]), diff --git a/inkycal/modules/inkycal_weather.py b/inkycal/modules/inkycal_weather.py index b525e58..053dc64 100644 --- a/inkycal/modules/inkycal_weather.py +++ b/inkycal/modules/inkycal_weather.py @@ -43,8 +43,8 @@ class Weather(inkycal_module): # module specific parameters self.owm = pyowm.OWM(self.config['api_key']) - self.units = 'metric' # metric # imperial - self.hour_format = '24' # 12 #24 + self.units = self.config['units'] + self.hour_format = self.config['hours'] self.timezone = get_system_tz() self.round_temperature = True self.round_windspeed = True @@ -278,7 +278,7 @@ class Weather(inkycal_module): 'temp':temp, 'icon':icon, 'stamp': forecast_timings[forecasts.index(forecast)].format('H.00' - if self.hour_format == '24' else 'h a') + if self.hour_format == 24 else 'h a') } elif self.forecast_interval == 'daily': @@ -335,10 +335,10 @@ class Weather(inkycal_module): sunrise_raw = arrow.get(weather.get_sunrise_time()).to(self.timezone) sunset_raw = arrow.get(weather.get_sunset_time()).to(self.timezone) - if self.hour_format == '12': + if self.hour_format == 12: sunrise = sunrise_raw.format('h:mm a') sunset = sunset_raw.format('h:mm a') - elif self.hour_format == '24': + elif self.hour_format == 24: sunrise = sunrise_raw.format('H:mm') sunset = sunset_raw.format('H:mm')