diff --git a/inkycal/custom/functions.py b/inkycal/custom/functions.py index 144da9f..9d6b9c4 100644 --- a/inkycal/custom/functions.py +++ b/inkycal/custom/functions.py @@ -11,7 +11,7 @@ from urllib.request import urlopen import os import time -logs = logging.getLogger('inkycal_custom') +logs = logging.getLogger(__name__) logs.setLevel(level=logging.INFO) # Get the path to the Inkycal folder @@ -26,14 +26,14 @@ image_folder = top_level + '/image_folder/' fonts = {} for path, dirs, files in os.walk(fonts_location): - for filename in files: - if filename.endswith('.otf'): - name = filename.split('.otf')[0] - fonts[name] = os.path.join(path, filename) + for _ in files: + if _.endswith('.otf'): + name = _.split('.otf')[0] + fonts[name] = os.path.join(path, _) - if filename.endswith('.ttf'): - name = filename.split('.ttf')[0] - fonts[name] = os.path.join(path, filename) + if _.endswith('.ttf'): + name = _.split('.ttf')[0] + fonts[name] = os.path.join(path, _) available_fonts = [key for key, values in fonts.items()] @@ -206,6 +206,7 @@ def text_wrap(text, font=None, max_width=None): Uses a Font object for more accurate calculations. Args: + - text -> Text as a string - font: A PIL font object which is used to calculate the size. - max_width: int-> a width in pixels defining the maximum width before splitting the text into the next chunk. diff --git a/inkycal/display/drivers/epdconfig.py b/inkycal/display/drivers/epdconfig.py index c8642f4..5755b9f 100644 --- a/inkycal/display/drivers/epdconfig.py +++ b/inkycal/display/drivers/epdconfig.py @@ -32,8 +32,7 @@ import logging import sys import time -filename = os.path.basename(__file__).split('.py')[0] -logger = logging.getLogger(filename) +logger = logging.getLogger(__name__) class RaspberryPi: diff --git a/inkycal/main.py b/inkycal/main.py index 727c597..58d0929 100644 --- a/inkycal/main.py +++ b/inkycal/main.py @@ -71,8 +71,7 @@ else: # Show less logging for PIL module logging.getLogger("PIL").setLevel(logging.WARNING) -filename = os.path.basename(__file__).split('.py')[0] -logger = logging.getLogger(filename) +logger = logging.getLogger(__name__) # TODO: autostart -> supervisor? diff --git a/inkycal/modules/dev_module.py b/inkycal/modules/dev_module.py index 6e37af2..0ff130f 100755 --- a/inkycal/modules/dev_module.py +++ b/inkycal/modules/dev_module.py @@ -38,8 +38,7 @@ except ImportError: ############################################################################# # Get the name of this file, set up logging for this filename -filename = os.path.basename(__file__).split('.py')[0] -logger = logging.getLogger(filename) +logger = logging.getLogger(__name__) ############################################################################# @@ -159,7 +158,7 @@ class Simple(inkycal_module): # -----------------------------------------------------------------------# # give an OK message - print(f'{filename} loaded') + print(f'{__name__} loaded') ############################################################################# # Validation of module specific parameters (optional) # @@ -220,7 +219,7 @@ class Simple(inkycal_module): if __name__ == '__main__': - print('running {0} in standalone mode'.format(filename)) + print('running {0} in standalone mode'.format(__name__)) ################################################################################ # Last steps diff --git a/inkycal/modules/ical_parser.py b/inkycal/modules/ical_parser.py index 5d92160..2ba5c19 100755 --- a/inkycal/modules/ical_parser.py +++ b/inkycal/modules/ical_parser.py @@ -22,8 +22,7 @@ from icalendar import Calendar local timezone. Converting all-day events to local timezone is a problem! """ -filename = os.path.basename(__file__).split('.py')[0] -logger = logging.getLogger(filename) +logger = logging.getLogger(__name__) class iCalendar: @@ -203,4 +202,4 @@ class iCalendar: if __name__ == '__main__': - print(f'running {filename} in standalone mode') + print(f'running {__name__} in standalone mode') diff --git a/inkycal/modules/inky_image.py b/inkycal/modules/inky_image.py index 2135a30..2e0f12c 100755 --- a/inkycal/modules/inky_image.py +++ b/inkycal/modules/inky_image.py @@ -15,8 +15,7 @@ import requests from PIL import Image -filename = os.path.basename(__file__).split('.py')[0] -logger = logging.getLogger(filename) +logger = logging.getLogger(__name__) class Inkyimage: @@ -30,7 +29,7 @@ class Inkyimage: self.image = image # give an OK message - logger.info(f'{filename} loaded') + logger.info(f'{__name__} loaded') def load(self, path): """loads an image from a URL or filepath. @@ -330,4 +329,4 @@ class Inkyimage: if __name__ == '__main__': - print(f'running {filename} in standalone/debug mode') + print(f'running {__name__} in standalone/debug mode') diff --git a/inkycal/modules/inkycal_agenda.py b/inkycal/modules/inkycal_agenda.py index 0254711..4f8f2dd 100755 --- a/inkycal/modules/inkycal_agenda.py +++ b/inkycal/modules/inkycal_agenda.py @@ -11,8 +11,7 @@ from inkycal.custom import * from inkycal.modules.ical_parser import iCalendar from inkycal.modules.template import inkycal_module -filename = os.path.basename(__file__).split('.py')[0] -logger = logging.getLogger(filename) +logger = logging.getLogger(__name__) class Agenda(inkycal_module): @@ -81,7 +80,7 @@ class Agenda(inkycal_module): self.timezone = get_system_tz() # give an OK message - print(f'{filename} loaded') + print(f'{__name__} loaded') def generate_image(self): """Generate image for this module""" @@ -228,4 +227,4 @@ class Agenda(inkycal_module): if __name__ == '__main__': - print(f'running {filename} in standalone mode') + print(f'running {__name__} in standalone mode') diff --git a/inkycal/modules/inkycal_calendar.py b/inkycal/modules/inkycal_calendar.py index 9432ba0..8d01330 100755 --- a/inkycal/modules/inkycal_calendar.py +++ b/inkycal/modules/inkycal_calendar.py @@ -10,8 +10,7 @@ from inkycal.custom import * import calendar as cal import arrow -filename = os.path.basename(__file__).split('.py')[0] -logger = logging.getLogger(filename) +logger = logging.getLogger(__name__) class Calendar(inkycal_module): @@ -86,7 +85,7 @@ class Calendar(inkycal_module): fonts['NotoSans-SemiCondensed'], size=self.fontsize) # give an OK message - print(f'{filename} loaded') + print(f'{__name__} loaded') def generate_image(self): """Generate image for this module""" @@ -341,4 +340,4 @@ class Calendar(inkycal_module): if __name__ == '__main__': - print(f'running {filename} in standalone mode') + print(f'running {__name__} in standalone mode') diff --git a/inkycal/modules/inkycal_feeds.py b/inkycal/modules/inkycal_feeds.py index 6b46090..c2a8dd2 100644 --- a/inkycal/modules/inkycal_feeds.py +++ b/inkycal/modules/inkycal_feeds.py @@ -13,8 +13,7 @@ from random import shuffle import feedparser -filename = os.path.basename(__file__).split('.py')[0] -logger = logging.getLogger(filename) +logger = logging.getLogger(__name__) class Feeds(inkycal_module): @@ -63,7 +62,7 @@ class Feeds(inkycal_module): self.shuffle_feeds = config["shuffle_feeds"] # give an OK message - print(f'{filename} loaded') + print(f'{__name__} loaded') def _validate(self): """Validate module-specific parameters""" @@ -155,4 +154,4 @@ class Feeds(inkycal_module): if __name__ == '__main__': - print(f'running {filename} in standalone/debug mode') + print(f'running {__name__} in standalone/debug mode') diff --git a/inkycal/modules/inkycal_image.py b/inkycal/modules/inkycal_image.py index 728c3d0..8eedeaf 100755 --- a/inkycal/modules/inkycal_image.py +++ b/inkycal/modules/inkycal_image.py @@ -10,8 +10,7 @@ from inkycal.custom import * from inkycal.modules.inky_image import Inkyimage as Images -filename = os.path.basename(__file__).split('.py')[0] -logger = logging.getLogger(filename) +logger = logging.getLogger(__name__) class Inkyimage(inkycal_module): @@ -66,7 +65,7 @@ class Inkyimage(inkycal_module): self.orientation = config['orientation'] # give an OK message - print(f'{filename} loaded') + print(f'{__name__} loaded') def generate_image(self): """Generate image for this module""" @@ -105,4 +104,4 @@ class Inkyimage(inkycal_module): if __name__ == '__main__': - print(f'running {filename} in standalone/debug mode') + print(f'running {__name__} in standalone/debug mode') diff --git a/inkycal/modules/inkycal_jokes.py b/inkycal/modules/inkycal_jokes.py index 773347f..10ac0e1 100755 --- a/inkycal/modules/inkycal_jokes.py +++ b/inkycal/modules/inkycal_jokes.py @@ -14,8 +14,7 @@ import requests # Show less logging for request module logging.getLogger("urllib3").setLevel(logging.WARNING) -filename = os.path.basename(__file__).split('.py')[0] -logger = logging.getLogger(filename) +logger = logging.getLogger(__name__) class Jokes(inkycal_module): @@ -33,7 +32,7 @@ class Jokes(inkycal_module): config = config['config'] # give an OK message - print(f'{filename} loaded') + print(f'{__name__} loaded') def generate_image(self): """Generate image for this module""" @@ -101,4 +100,4 @@ class Jokes(inkycal_module): if __name__ == '__main__': - print(f'running {filename} in standalone/debug mode') + print(f'running {__name__} in standalone/debug mode') diff --git a/inkycal/modules/inkycal_server.py b/inkycal/modules/inkycal_server.py index 04105e8..86b6820 100755 --- a/inkycal/modules/inkycal_server.py +++ b/inkycal/modules/inkycal_server.py @@ -13,8 +13,7 @@ from inkycal.custom import * from inkycal.modules.inky_image import Inkyimage as Images -filename = os.path.basename(__file__).split('.py')[0] -logger = logging.getLogger(filename) +logger = logging.getLogger(__name__) class Inkyserver(inkycal_module): @@ -73,7 +72,7 @@ class Inkyserver(inkycal_module): self.path_body = config['path_body'] # give an OK message - print(f'{filename} loaded') + print(f'{__name__} loaded') def generate_image(self): """Generate image for this module""" @@ -122,7 +121,7 @@ class Inkyserver(inkycal_module): if __name__ == '__main__': - print(f'running {filename} in standalone/debug mode') + print(f'running {__name__} in standalone/debug mode') ## 'https://inkycal.robertsirre.nl/panel/calendar/{model}?width={width}&height={height}' ##path = path.replace('{model}', model).replace('{width}',str(display_width)).replace('{height}',str(display_height)) diff --git a/inkycal/modules/inkycal_slideshow.py b/inkycal/modules/inkycal_slideshow.py index 929bb15..68f1eb5 100755 --- a/inkycal/modules/inkycal_slideshow.py +++ b/inkycal/modules/inkycal_slideshow.py @@ -12,8 +12,7 @@ from inkycal.custom import * # PIL has a class named Image, use alias for Inkyimage -> Images from inkycal.modules.inky_image import Inkyimage as Images -filename = os.path.basename(__file__).split('.py')[0] -logger = logging.getLogger(filename) +logger = logging.getLogger(__name__) class Slideshow(inkycal_module): @@ -80,7 +79,7 @@ class Slideshow(inkycal_module): self._first_run = True # give an OK message - print(f'{filename} loaded') + print(f'{__name__} loaded') def generate_image(self): """Generate image for this module""" @@ -132,4 +131,4 @@ class Slideshow(inkycal_module): if __name__ == '__main__': - print(f'running {filename} in standalone/debug mode') + print(f'running {__name__} in standalone/debug mode') diff --git a/inkycal/modules/inkycal_weather.py b/inkycal/modules/inkycal_weather.py index 2fa458d..ba470f6 100755 --- a/inkycal/modules/inkycal_weather.py +++ b/inkycal/modules/inkycal_weather.py @@ -8,13 +8,13 @@ Copyright by aceisace from inkycal.modules.template import inkycal_module from inkycal.custom import * -import math, decimal +import math +import decimal import arrow from pyowm.owm import OWM -filename = os.path.basename(__file__).split('.py')[0] -logger = logging.getLogger(filename) +logger = logging.getLogger(__name__) class Weather(inkycal_module): @@ -102,7 +102,7 @@ class Weather(inkycal_module): fonts['weathericons-regular-webfont'], size=self.fontsize) # give an OK message - print(f"{filename} loaded") + print(f"{__name__} loaded") def generate_image(self): """Generate image for this module""" @@ -505,4 +505,4 @@ class Weather(inkycal_module): if __name__ == '__main__': - print(f'running {filename} in standalone mode') + print(f'running {__name__} in standalone mode') diff --git a/inkycal/tests/__init__.py b/inkycal/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/inkycal/tests/inkycal_calendar_test.py b/inkycal/tests/inkycal_calendar_test.py index 37f0e1f..0ddaffa 100755 --- a/inkycal/tests/inkycal_calendar_test.py +++ b/inkycal/tests/inkycal_calendar_test.py @@ -80,7 +80,7 @@ class module_test(unittest.TestCase): module = Module(test) im_black, im_colour = module.generate_image() print('OK') - if use_preview == True and environment == 'Raspberry': + if use_preview and environment == 'Raspberry': preview(merge(im_black, im_colour)) diff --git a/inkycal/tests/inkycal_weather_test.py b/inkycal/tests/inkycal_weather_test.py index 60f423d..9dbd051 100755 --- a/inkycal/tests/inkycal_weather_test.py +++ b/inkycal/tests/inkycal_weather_test.py @@ -181,7 +181,7 @@ class module_test(unittest.TestCase): module = Module(test) im_black, im_colour = module.generate_image() print('OK') - if use_preview == True and environment == 'Raspberry': + if use_preview and environment == 'Raspberry': preview(merge(im_black, im_colour)) else: print('No key given, omitted testing')