Minor code improvements
This commit is contained in:
		| @@ -1 +1,2 @@ | |||||||
| from .functions import * | from .functions import * | ||||||
|  | from .inkycal_exceptions import * | ||||||
|   | |||||||
| @@ -243,7 +243,7 @@ def internet_available(): | |||||||
|  |  | ||||||
|     Returned output can be used to add a check for internet availability: |     Returned output can be used to add a check for internet availability: | ||||||
|  |  | ||||||
|     >>> if internet_available() == True: |     >>> if internet_available(): | ||||||
|     >>> #...do something that requires internet connectivity |     >>> #...do something that requires internet connectivity | ||||||
|     """ |     """ | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										16
									
								
								inkycal/custom/inkycal_exceptions.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								inkycal/custom/inkycal_exceptions.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,16 @@ | |||||||
|  | #!python3 | ||||||
|  | """ | ||||||
|  | Inkycal custom Exceptions | ||||||
|  | """ | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class SettingsFileNotFoundError(Exception): | ||||||
|  |     def __init__(self, message="Inkycal could not find a settings.json file. Please check the settings-file path"): | ||||||
|  |         self.message = message | ||||||
|  |         super().__init__(self.message) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class NetworkNotReachableError(Exception): | ||||||
|  |     def __init__(self, message="Inkycal could not establish a connection to the web"): | ||||||
|  |         self.message = message | ||||||
|  |         super().__init__(self.message) | ||||||
| @@ -109,9 +109,7 @@ class Inkycal: | |||||||
|                     self.settings = settings |                     self.settings = settings | ||||||
|  |  | ||||||
|             except FileNotFoundError: |             except FileNotFoundError: | ||||||
|                 print('No settings file found in given path\n' |                 raise SettingsFileNotFoundError | ||||||
|                       'Please double check your settings_path') |  | ||||||
|                 return |  | ||||||
|  |  | ||||||
|         else: |         else: | ||||||
|             try: |             try: | ||||||
| @@ -120,8 +118,7 @@ class Inkycal: | |||||||
|                     self.settings = settings |                     self.settings = settings | ||||||
|  |  | ||||||
|             except FileNotFoundError: |             except FileNotFoundError: | ||||||
|                 print('No settings file found in /boot') |                 raise SettingsFileNotFoundError | ||||||
|                 return |  | ||||||
|  |  | ||||||
|         # Option to use epaper image optimisation, reduces colours |         # Option to use epaper image optimisation, reduces colours | ||||||
|         self.optimize = True |         self.optimize = True | ||||||
|   | |||||||
| @@ -115,7 +115,7 @@ class Simple(inkycal_module): | |||||||
|         # Check if all required parameters are present |         # Check if all required parameters are present | ||||||
|         # remove this if your module has no required parameters |         # remove this if your module has no required parameters | ||||||
|         for param in self.requires: |         for param in self.requires: | ||||||
|             if not param in config: |             if param not in config: | ||||||
|                 raise Exception('config is missing {}'.format(param)) |                 raise Exception('config is missing {}'.format(param)) | ||||||
|  |  | ||||||
|         # the web-UI removes any blank space from the input |         # the web-UI removes any blank space from the input | ||||||
|   | |||||||
| @@ -4,6 +4,15 @@ | |||||||
| iCalendar (parsing) module for Inky-Calendar Project | iCalendar (parsing) module for Inky-Calendar Project | ||||||
| Copyright by aceisace | Copyright by aceisace | ||||||
| """ | """ | ||||||
|  | import urllib | ||||||
|  | import arrow | ||||||
|  | from urllib.request import urlopen | ||||||
|  | import logging | ||||||
|  | import time | ||||||
|  | import os | ||||||
|  |  | ||||||
|  | import recurring_ical_events | ||||||
|  | from icalendar import Calendar | ||||||
|  |  | ||||||
| """               ---info about iCalendars--- | """               ---info about iCalendars--- | ||||||
| • all day events start at midnight, ending at midnight of the next day | • all day events start at midnight, ending at midnight of the next day | ||||||
| @@ -13,24 +22,6 @@ Copyright by aceisace | |||||||
|   local timezone. Converting all-day events to local timezone is a problem! |   local timezone. Converting all-day events to local timezone is a problem! | ||||||
| """ | """ | ||||||
|  |  | ||||||
| import arrow |  | ||||||
| from urllib.request import urlopen |  | ||||||
| import logging |  | ||||||
| import time |  | ||||||
| import os |  | ||||||
|  |  | ||||||
| try: |  | ||||||
|     import recurring_ical_events |  | ||||||
| except ModuleNotFoundError: |  | ||||||
|     print('recurring-ical-events library could not be found.') |  | ||||||
|     print('Please install this with: pip3 install recurring-ical-events') |  | ||||||
|  |  | ||||||
| try: |  | ||||||
|     from icalendar import Calendar, Event |  | ||||||
| except ModuleNotFoundError: |  | ||||||
|     print('icalendar library could not be found. Please install this with:') |  | ||||||
|     print('pip3 install icalendar') |  | ||||||
|  |  | ||||||
| filename = os.path.basename(__file__).split('.py')[0] | filename = os.path.basename(__file__).split('.py')[0] | ||||||
| logger = logging.getLogger(filename) | logger = logging.getLogger(filename) | ||||||
|  |  | ||||||
| @@ -49,20 +40,6 @@ class iCalendar: | |||||||
|         add username and password to access protected files |         add username and password to access protected files | ||||||
|         """ |         """ | ||||||
|  |  | ||||||
|         if type(url) == list: |  | ||||||
|             if (username == None) and (password == None): |  | ||||||
|                 ical = [Calendar.from_ical(str(urlopen(_).read().decode())) |  | ||||||
|                         for _ in url] |  | ||||||
|             else: |  | ||||||
|                 ical = [auth_ical(each_url, username, password) for each_url in url] |  | ||||||
|         elif type(url) == str: |  | ||||||
|             if (username == None) and (password == None): |  | ||||||
|                 ical = [Calendar.from_ical(str(urlopen(url).read().decode()))] |  | ||||||
|             else: |  | ||||||
|                 ical = [auth_ical(url, username, password)] |  | ||||||
|         else: |  | ||||||
|             raise Exception(f"Input: '{url}' is not a string or list!") |  | ||||||
|  |  | ||||||
|         def auth_ical(url, uname, passwd): |         def auth_ical(url, uname, passwd): | ||||||
|             """Authorisation helper for protected ical files""" |             """Authorisation helper for protected ical files""" | ||||||
|  |  | ||||||
| @@ -74,6 +51,20 @@ class iCalendar: | |||||||
|             ical = Calendar.from_ical(str(opener.open(url).read().decode())) |             ical = Calendar.from_ical(str(opener.open(url).read().decode())) | ||||||
|             return ical |             return ical | ||||||
|  |  | ||||||
|  |         if type(url) == list: | ||||||
|  |             if (username is None) and (password is None): | ||||||
|  |                 ical = [Calendar.from_ical(str(urlopen(_).read().decode())) | ||||||
|  |                         for _ in url] | ||||||
|  |             else: | ||||||
|  |                 ical = [auth_ical(each_url, username, password) for each_url in url] | ||||||
|  |         elif type(url) == str: | ||||||
|  |             if (username is None) and (password is None): | ||||||
|  |                 ical = [Calendar.from_ical(str(urlopen(url).read().decode()))] | ||||||
|  |             else: | ||||||
|  |                 ical = [auth_ical(url, username, password)] | ||||||
|  |         else: | ||||||
|  |             raise Exception(f"Input: '{url}' is not a string or list!") | ||||||
|  |  | ||||||
|         # Add the parsed icalendar/s to the self.icalendars list |         # Add the parsed icalendar/s to the self.icalendars list | ||||||
|         if ical: self.icalendars += ical |         if ical: self.icalendars += ical | ||||||
|         logger.info('loaded iCalendars from URLs') |         logger.info('loaded iCalendars from URLs') | ||||||
| @@ -106,7 +97,7 @@ class iCalendar: | |||||||
|         Returns a list of events sorted by date |         Returns a list of events sorted by date | ||||||
|         """ |         """ | ||||||
|         if type(timeline_start) == arrow.arrow.Arrow: |         if type(timeline_start) == arrow.arrow.Arrow: | ||||||
|             if timezone == None: |             if timezone is None: | ||||||
|                 timezone = 'UTC' |                 timezone = 'UTC' | ||||||
|             t_start = timeline_start |             t_start = timeline_start | ||||||
|             t_end = timeline_end |             t_end = timeline_end | ||||||
|   | |||||||
| @@ -9,7 +9,7 @@ images. | |||||||
| Copyright by aceisace | Copyright by aceisace | ||||||
| """ | """ | ||||||
|  |  | ||||||
| from PIL import Image, ImageOps, ImageColor | from PIL import Image | ||||||
| import requests | import requests | ||||||
| import numpy | import numpy | ||||||
| import os | import os | ||||||
| @@ -134,12 +134,12 @@ class Inkyimage: | |||||||
|  |  | ||||||
|             image = self.image |             image = self.image | ||||||
|             if layout == 'horizontal': |             if layout == 'horizontal': | ||||||
|                 if (image.height > image.width): |                 if image.height > image.width: | ||||||
|                     logger.info('image width greater than image height, flipping') |                     logger.info('image width greater than image height, flipping') | ||||||
|                     image = image.rotate(90, expand=True) |                     image = image.rotate(90, expand=True) | ||||||
|  |  | ||||||
|             elif layout == 'vertical': |             elif layout == 'vertical': | ||||||
|                 if (image.width > image.height): |                 if image.width > image.height: | ||||||
|                     logger.info('image width greater than image height, flipping') |                     logger.info('image width greater than image height, flipping') | ||||||
|                     image = image.rotate(90, expand=True) |                     image = image.rotate(90, expand=True) | ||||||
|             else: |             else: | ||||||
| @@ -242,7 +242,7 @@ class Inkyimage: | |||||||
|         if self._image_loaded(): |         if self._image_loaded(): | ||||||
|             image = self.image.convert('RGB') |             image = self.image.convert('RGB') | ||||||
|         else: |         else: | ||||||
|             logger.error('No image loaded') |             raise FileNotFoundError | ||||||
|  |  | ||||||
|         if palette == 'bwr': |         if palette == 'bwr': | ||||||
|             # black-white-red palette |             # black-white-red palette | ||||||
|   | |||||||
| @@ -5,12 +5,11 @@ Agenda module for Inky-Calendar Project | |||||||
| Copyright by aceisace | Copyright by aceisace | ||||||
| """ | """ | ||||||
|  |  | ||||||
| from inkycal.modules.template import inkycal_module | import arrow | ||||||
|  |  | ||||||
| from inkycal.custom import * | from inkycal.custom import * | ||||||
| from inkycal.modules.ical_parser import iCalendar | from inkycal.modules.ical_parser import iCalendar | ||||||
|  | from inkycal.modules.template import inkycal_module | ||||||
| import calendar as cal |  | ||||||
| import arrow |  | ||||||
|  |  | ||||||
| filename = os.path.basename(__file__).split('.py')[0] | filename = os.path.basename(__file__).split('.py')[0] | ||||||
| logger = logging.getLogger(filename) | logger = logging.getLogger(filename) | ||||||
| @@ -58,9 +57,8 @@ class Agenda(inkycal_module): | |||||||
|  |  | ||||||
|         # Check if all required parameters are present |         # Check if all required parameters are present | ||||||
|         for param in self.requires: |         for param in self.requires: | ||||||
|             if not param in config: |             if param not in config: | ||||||
|                 raise Exception(f'config is missing {param}') |                 raise Exception(f'config is missing {param}') | ||||||
|                 logger.exception(f'config is missing "{param}"') |  | ||||||
|  |  | ||||||
|         # module specific parameters |         # module specific parameters | ||||||
|         self.date_format = config['date_format'] |         self.date_format = config['date_format'] | ||||||
| @@ -184,7 +182,7 @@ class Agenda(inkycal_module): | |||||||
|                 title = _['title'] |                 title = _['title'] | ||||||
|  |  | ||||||
|                 # Check if item is a date |                 # Check if item is a date | ||||||
|                 if not 'end' in _: |                 if 'end' not in _: | ||||||
|                     ImageDraw.Draw(im_colour).line( |                     ImageDraw.Draw(im_colour).line( | ||||||
|                         (0, line_pos[cursor][1], im_width, line_pos[cursor][1]), |                         (0, line_pos[cursor][1], im_width, line_pos[cursor][1]), | ||||||
|                         fill='black') |                         fill='black') | ||||||
| @@ -199,7 +197,7 @@ class Agenda(inkycal_module): | |||||||
|                     time = _['begin'].format(self.time_format) |                     time = _['begin'].format(self.time_format) | ||||||
|  |  | ||||||
|                     # Check if event is all day, if not, add the time |                     # Check if event is all day, if not, add the time | ||||||
|                     if parser.all_day(_) == False: |                     if not parser.all_day(_): | ||||||
|                         write(im_black, (x_time, line_pos[cursor][1]), |                         write(im_black, (x_time, line_pos[cursor][1]), | ||||||
|                               (time_width, line_height), time, |                               (time_width, line_height), time, | ||||||
|                               font=self.font, alignment='left') |                               font=self.font, alignment='left') | ||||||
|   | |||||||
| @@ -108,7 +108,7 @@ class Calendar(inkycal_module): | |||||||
|         logger.debug(f"month_name_height: {month_name_height}") |         logger.debug(f"month_name_height: {month_name_height}") | ||||||
|         logger.debug(f"weekdays_height: {weekdays_height}") |         logger.debug(f"weekdays_height: {weekdays_height}") | ||||||
|  |  | ||||||
|         if self.show_events == True: |         if self.show_events: | ||||||
|             logger.debug("Allocating space for events") |             logger.debug("Allocating space for events") | ||||||
|             calendar_height = int(im_height * 0.6) |             calendar_height = int(im_height * 0.6) | ||||||
|             events_height = im_height - month_name_height - weekdays_height - calendar_height |             events_height = im_height - month_name_height - weekdays_height - calendar_height | ||||||
| @@ -207,7 +207,7 @@ class Calendar(inkycal_module): | |||||||
|         im_colour.paste(icon, current_day_pos, icon) |         im_colour.paste(icon, current_day_pos, icon) | ||||||
|  |  | ||||||
|         # If events should be loaded and shown... |         # If events should be loaded and shown... | ||||||
|         if self.show_events == True: |         if self.show_events: | ||||||
|  |  | ||||||
|             # If this month requires 5 instead of 6 rows, increase event section height |             # If this month requires 5 instead of 6 rows, increase event section height | ||||||
|             if len(cal.monthcalendar(now.year, now.month)) == 5: |             if len(cal.monthcalendar(now.year, now.month)) == 5: | ||||||
| @@ -277,7 +277,7 @@ class Calendar(inkycal_module): | |||||||
|             self._upcoming_events = upcoming_events |             self._upcoming_events = upcoming_events | ||||||
|  |  | ||||||
|             # delete events which won't be able to fit (more events than lines) |             # delete events which won't be able to fit (more events than lines) | ||||||
|             upcoming_events[:max_event_lines] |             upcoming_events = upcoming_events[:max_event_lines] | ||||||
|  |  | ||||||
|             # Check if any events were found in the given timerange |             # Check if any events were found in the given timerange | ||||||
|             if upcoming_events: |             if upcoming_events: | ||||||
| @@ -315,7 +315,7 @@ class Calendar(inkycal_module): | |||||||
|                                   date, font=self.font, alignment='left') |                                   date, font=self.font, alignment='left') | ||||||
|  |  | ||||||
|                             # Check if event is all day |                             # Check if event is all day | ||||||
|                             if parser.all_day(event) == True: |                             if parser.all_day(event): | ||||||
|                                 write(im_black, (date_width, event_lines[cursor][1]), |                                 write(im_black, (date_width, event_lines[cursor][1]), | ||||||
|                                       (event_width_l, line_height), name, font=self.font, |                                       (event_width_l, line_height), name, font=self.font, | ||||||
|                                       alignment='left') |                                       alignment='left') | ||||||
|   | |||||||
| @@ -11,11 +11,7 @@ from inkycal.custom import * | |||||||
|  |  | ||||||
| from random import shuffle | from random import shuffle | ||||||
|  |  | ||||||
| try: |  | ||||||
| import feedparser | import feedparser | ||||||
| except ImportError: |  | ||||||
|     print('feedparser is not installed! Please install with:') |  | ||||||
|     print('pip3 install feedparser') |  | ||||||
|  |  | ||||||
| filename = os.path.basename(__file__).split('.py')[0] | filename = os.path.basename(__file__).split('.py')[0] | ||||||
| logger = logging.getLogger(filename) | logger = logging.getLogger(filename) | ||||||
| @@ -54,7 +50,7 @@ class Feeds(inkycal_module): | |||||||
|  |  | ||||||
|         # Check if all required parameters are present |         # Check if all required parameters are present | ||||||
|         for param in self.requires: |         for param in self.requires: | ||||||
|             if not param in config: |             if param not in config: | ||||||
|                 raise Exception(f'config is missing {param}') |                 raise Exception(f'config is missing {param}') | ||||||
|  |  | ||||||
|         # required parameters |         # required parameters | ||||||
| @@ -89,10 +85,10 @@ class Feeds(inkycal_module): | |||||||
|         im_colour = Image.new('RGB', size=im_size, color='white') |         im_colour = Image.new('RGB', size=im_size, color='white') | ||||||
|  |  | ||||||
|         # Check if internet is available |         # Check if internet is available | ||||||
|         if internet_available() == True: |         if internet_available(): | ||||||
|             logger.info('Connection test passed') |             logger.info('Connection test passed') | ||||||
|         else: |         else: | ||||||
|             raise Exception('Network could not be reached :/') |             raise NetworkNotReachableError | ||||||
|  |  | ||||||
|         # Set some parameters for formatting feeds |         # Set some parameters for formatting feeds | ||||||
|         line_spacing = 1 |         line_spacing = 1 | ||||||
| @@ -119,7 +115,7 @@ class Feeds(inkycal_module): | |||||||
|         self._parsed_feeds = parsed_feeds |         self._parsed_feeds = parsed_feeds | ||||||
|  |  | ||||||
|         # Shuffle the list to prevent showing the same content |         # Shuffle the list to prevent showing the same content | ||||||
|         if self.shuffle_feeds == True: |         if self.shuffle_feeds: | ||||||
|             shuffle(parsed_feeds) |             shuffle(parsed_feeds) | ||||||
|  |  | ||||||
|         # Trim down the list to the max number of lines |         # Trim down the list to the max number of lines | ||||||
|   | |||||||
| @@ -88,7 +88,7 @@ class Inkyimage(inkycal_module): | |||||||
|         im.remove_alpha() |         im.remove_alpha() | ||||||
|  |  | ||||||
|         # if autoflip was enabled, flip the image |         # if autoflip was enabled, flip the image | ||||||
|         if self.autoflip == True: |         if self.autoflip: | ||||||
|             im.autoflip(self.orientation) |             im.autoflip(self.orientation) | ||||||
|  |  | ||||||
|         # resize the image so it can fit on the epaper |         # resize the image so it can fit on the epaper | ||||||
|   | |||||||
| @@ -49,10 +49,10 @@ class Jokes(inkycal_module): | |||||||
|         im_colour = Image.new('RGB', size=im_size, color='white') |         im_colour = Image.new('RGB', size=im_size, color='white') | ||||||
|  |  | ||||||
|         # Check if internet is available |         # Check if internet is available | ||||||
|         if internet_available() == True: |         if internet_available(): | ||||||
|             logger.info('Connection test passed') |             logger.info('Connection test passed') | ||||||
|         else: |         else: | ||||||
|             raise Exception('Network could not be reached :/') |             raise NetworkNotReachableError | ||||||
|  |  | ||||||
|         # Set some parameters for formatting feeds |         # Set some parameters for formatting feeds | ||||||
|         line_spacing = 1 |         line_spacing = 1 | ||||||
|   | |||||||
| @@ -58,7 +58,7 @@ class Inkyserver(inkycal_module): | |||||||
|  |  | ||||||
|         # required parameters |         # required parameters | ||||||
|         for param in self.requires: |         for param in self.requires: | ||||||
|             if not param in config: |             if param not in config: | ||||||
|                 raise Exception(f'config is missing {param}') |                 raise Exception(f'config is missing {param}') | ||||||
|  |  | ||||||
|         # optional parameters |         # optional parameters | ||||||
|   | |||||||
| @@ -97,7 +97,7 @@ class Slideshow(inkycal_module): | |||||||
|             return somelist[1:] + somelist[:1] |             return somelist[1:] + somelist[:1] | ||||||
|  |  | ||||||
|         # Switch to the next image if this is not the first run |         # Switch to the next image if this is not the first run | ||||||
|         if self._first_run == True: |         if self._first_run: | ||||||
|             self._first_run = False |             self._first_run = False | ||||||
|         else: |         else: | ||||||
|             self.images = rotate(self.images) |             self.images = rotate(self.images) | ||||||
| @@ -115,7 +115,7 @@ class Slideshow(inkycal_module): | |||||||
|         im.remove_alpha() |         im.remove_alpha() | ||||||
|  |  | ||||||
|         # if autoflip was enabled, flip the image |         # if autoflip was enabled, flip the image | ||||||
|         if self.autoflip == True: |         if self.autoflip: | ||||||
|             im.autoflip(self.orientation) |             im.autoflip(self.orientation) | ||||||
|  |  | ||||||
|         # resize the image so it can fit on the epaper |         # resize the image so it can fit on the epaper | ||||||
|   | |||||||
| @@ -8,11 +8,7 @@ Copyright by aceisace | |||||||
| from inkycal.modules.template import inkycal_module | from inkycal.modules.template import inkycal_module | ||||||
| from inkycal.custom import * | from inkycal.custom import * | ||||||
|  |  | ||||||
| try: |  | ||||||
| import todoist | import todoist | ||||||
| except ImportError: |  | ||||||
|     print('todoist is not installed! Please install with:') |  | ||||||
|     print('pip3 install todoist-python') |  | ||||||
|  |  | ||||||
| filename = os.path.basename(__file__).split('.py')[0] | filename = os.path.basename(__file__).split('.py')[0] | ||||||
| logger = logging.getLogger(filename) | logger = logging.getLogger(filename) | ||||||
| @@ -20,7 +16,7 @@ logger = logging.getLogger(filename) | |||||||
|  |  | ||||||
| class Todoist(inkycal_module): | class Todoist(inkycal_module): | ||||||
|     """Todoist api class |     """Todoist api class | ||||||
|     parses todo's from api-key |     parses todos from api-key | ||||||
|     """ |     """ | ||||||
|  |  | ||||||
|     name = "Todoist API - show your todos from todoist" |     name = "Todoist API - show your todos from todoist" | ||||||
| @@ -47,7 +43,7 @@ class Todoist(inkycal_module): | |||||||
|  |  | ||||||
|         # Check if all required parameters are present |         # Check if all required parameters are present | ||||||
|         for param in self.requires: |         for param in self.requires: | ||||||
|             if not param in config: |             if param not in config: | ||||||
|                 raise Exception(f'config is missing {param}') |                 raise Exception(f'config is missing {param}') | ||||||
|  |  | ||||||
|         # module specific parameters |         # module specific parameters | ||||||
| @@ -84,11 +80,11 @@ class Todoist(inkycal_module): | |||||||
|         im_colour = Image.new('RGB', size=im_size, color='white') |         im_colour = Image.new('RGB', size=im_size, color='white') | ||||||
|  |  | ||||||
|         # Check if internet is available |         # Check if internet is available | ||||||
|         if internet_available() == True: |         if internet_available(): | ||||||
|             logger.info('Connection test passed') |             logger.info('Connection test passed') | ||||||
|             self._api.sync() |             self._api.sync() | ||||||
|         else: |         else: | ||||||
|             raise Exception('Network could not be reached :/') |             raise NetworkNotReachableError | ||||||
|  |  | ||||||
|         # Set some parameters for formatting todos |         # Set some parameters for formatting todos | ||||||
|         line_spacing = 1 |         line_spacing = 1 | ||||||
| @@ -134,7 +130,7 @@ class Todoist(inkycal_module): | |||||||
|         simplified = [ |         simplified = [ | ||||||
|             { |             { | ||||||
|                 'name': task['content'], |                 'name': task['content'], | ||||||
|                 'due': task['due']['string'] if task['due'] != None else "", |                 'due': task['due']['string'] if task['due'] is not None else "", | ||||||
|                 'priority': task['priority'], |                 'priority': task['priority'], | ||||||
|                 'project': all_projects[task['project_id']] if task['project_id'] in all_projects else "deleted" |                 'project': all_projects[task['project_id']] if task['project_id'] in all_projects else "deleted" | ||||||
|             } |             } | ||||||
| @@ -170,13 +166,13 @@ class Todoist(inkycal_module): | |||||||
|                     if cursor < len(line_positions): |                     if cursor < len(line_positions): | ||||||
|                         line_x, line_y = line_positions[cursor] |                         line_x, line_y = line_positions[cursor] | ||||||
|  |  | ||||||
|                         # Add todo project name |                         # Add todos project name | ||||||
|                         write( |                         write( | ||||||
|                             im_colour, line_positions[cursor], |                             im_colour, line_positions[cursor], | ||||||
|                             (project_width, line_height), |                             (project_width, line_height), | ||||||
|                             todo['project'], font=self.font, alignment='left') |                             todo['project'], font=self.font, alignment='left') | ||||||
|  |  | ||||||
|                         # Add todo due if not empty |                         # Add todos due if not empty | ||||||
|                         if todo['due'] != "": |                         if todo['due'] != "": | ||||||
|                             write( |                             write( | ||||||
|                                 im_black, |                                 im_black, | ||||||
| @@ -184,7 +180,7 @@ class Todoist(inkycal_module): | |||||||
|                                 (due_width, line_height), |                                 (due_width, line_height), | ||||||
|                                 todo['due'], font=self.font, alignment='left') |                                 todo['due'], font=self.font, alignment='left') | ||||||
|  |  | ||||||
|                         # Add todo name |                         # Add todos name | ||||||
|                         write( |                         write( | ||||||
|                             im_black, |                             im_black, | ||||||
|                             (line_x + project_width + due_width, line_y), |                             (line_x + project_width + due_width, line_y), | ||||||
|   | |||||||
| @@ -10,13 +10,8 @@ from inkycal.custom import * | |||||||
|  |  | ||||||
| import math, decimal | import math, decimal | ||||||
| import arrow | import arrow | ||||||
| from locale import getdefaultlocale as sys_locale |  | ||||||
|  |  | ||||||
| try: |  | ||||||
| from pyowm.owm import OWM | from pyowm.owm import OWM | ||||||
| except ImportError: |  | ||||||
|     print('pyowm is not installed! Please install with:') |  | ||||||
|     print('pip3 install pyowm') |  | ||||||
|  |  | ||||||
| filename = os.path.basename(__file__).split('.py')[0] | filename = os.path.basename(__file__).split('.py')[0] | ||||||
| logger = logging.getLogger(filename) | logger = logging.getLogger(filename) | ||||||
| @@ -123,11 +118,10 @@ class Weather(inkycal_module): | |||||||
|         im_colour = Image.new('RGB', size=im_size, color='white') |         im_colour = Image.new('RGB', size=im_size, color='white') | ||||||
|  |  | ||||||
|         # Check if internet is available |         # Check if internet is available | ||||||
|         if internet_available() == True: |         if internet_available(): | ||||||
|             logger.info('Connection test passed') |             logger.info('Connection test passed') | ||||||
|         else: |         else: | ||||||
|             logger.exception('Network could not be reached :(') |             raise NetworkNotReachableError | ||||||
|             raise |  | ||||||
|  |  | ||||||
|         def get_moon_phase(): |         def get_moon_phase(): | ||||||
|             """Calculate the current (approximate) moon phase""" |             """Calculate the current (approximate) moon phase""" | ||||||
| @@ -426,11 +420,11 @@ class Weather(inkycal_module): | |||||||
|             sunset = sunset_raw.format('H:mm') |             sunset = sunset_raw.format('H:mm') | ||||||
|  |  | ||||||
|         # Format the windspeed to user preference |         # Format the windspeed to user preference | ||||||
|         if self.use_beaufort == True: |         if self.use_beaufort: | ||||||
|             logger.debug("using beaufort for wind") |             logger.debug("using beaufort for wind") | ||||||
|             wind = str(weather.wind(unit='beaufort')['speed']) |             wind = str(weather.wind(unit='beaufort')['speed']) | ||||||
|  |  | ||||||
|         elif self.use_beaufort == False: |         else: | ||||||
|  |  | ||||||
|             if self.units == 'metric': |             if self.units == 'metric': | ||||||
|                 logging.debug('getting windspeed in metric unit') |                 logging.debug('getting windspeed in metric unit') | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user