Best practices & code cleanup

This commit is contained in:
Ace
2023-12-18 12:46:33 +01:00
parent ad0610635e
commit e710964e10
29 changed files with 1241 additions and 1228 deletions

View File

@@ -1,5 +1,3 @@
#!python3
"""
Third party module template (inkycal-compatible module)

View File

@@ -1,6 +1,3 @@
#!python3
"""
Custom image class for Inkycal Project
Takes care of handling images. Made to be used by other modules to handle
@@ -14,7 +11,6 @@ import os
import PIL
import numpy
import requests
from PIL import Image
logger = logging.getLogger(__name__)
@@ -116,7 +112,7 @@ class Inkyimage:
self.image = image
logger.info(f'flipped image by {angle} degrees')
def autoflip(self, layout:str) -> None:
def autoflip(self, layout: str) -> None:
"""flips the image automatically to the given layout.
Args:
@@ -335,4 +331,3 @@ class Inkyimage:
if __name__ == '__main__':
print(f'running {__name__} in standalone/debug mode')

View File

@@ -1,14 +1,11 @@
#!python3
"""
Inkycal Image Module
Copyright by aceinnolab
"""
from inkycal.modules.template import inkycal_module
from inkycal.custom import *
from inkycal.modules.inky_image import Inkyimage as Images
from inkycal.modules.template import inkycal_module
logger = logging.getLogger(__name__)

View File

@@ -1,17 +1,12 @@
#!python3
"""
Inkycal-server module for Inkycal Project
by Aterju (https://inkycal.robertsirre.nl/)
Copyright by aceinnolab
"""
import requests
from inkycal.modules.template import inkycal_module
from inkycal.custom import *
from inkycal.modules.inky_image import Inkyimage as Images
from inkycal.modules.template import inkycal_module
logger = logging.getLogger(__name__)

View File

@@ -1,16 +1,13 @@
#!python3
"""
Inkycal Slideshow Module
Copyright by aceinnolab
"""
import glob
from inkycal.modules.template import inkycal_module
from inkycal.custom import *
# PIL has a class named Image, use alias for Inkyimage -> Images
from inkycal.modules.inky_image import Inkyimage as Images
from inkycal.modules.template import inkycal_module
logger = logging.getLogger(__name__)

View File

@@ -1,18 +1,16 @@
#!python3
"""
Inkycal weather module
Copyright by aceinnolab
"""
from inkycal.modules.template import inkycal_module
from inkycal.custom import *
import math
import decimal
import math
import arrow
from inkycal.custom import *
from inkycal.custom import OpenWeatherMap
from inkycal.modules.template import inkycal_module
logger = logging.getLogger(__name__)
@@ -95,7 +93,7 @@ class Weather(inkycal_module):
self.use_beaufort = config['use_beaufort']
# additional configuration
self.owm = OpenWeatherMap(api_key=self.api_key, city_id=self.location, units=config['units'])
self.owm = OpenWeatherMap(api_key=self.api_key, city_id=self.location, units=config['units'])
self.timezone = get_system_tz()
self.locale = config['language']
self.weatherfont = ImageFont.truetype(
@@ -104,9 +102,8 @@ class Weather(inkycal_module):
# give an OK message
print(f"{__name__} loaded")
@staticmethod
def mps_to_beaufort(meters_per_second:float) -> int:
def mps_to_beaufort(meters_per_second: float) -> int:
"""Map meters per second to the beaufort scale.
Args:
@@ -120,7 +117,7 @@ class Weather(inkycal_module):
return next((i for i, threshold in enumerate(thresholds) if meters_per_second < threshold), 11)
@staticmethod
def mps_to_mph(meters_per_second:float) -> float:
def mps_to_mph(meters_per_second: float) -> float:
"""Map meters per second to miles per hour, rounded to one decimal place.
Args:
@@ -135,7 +132,7 @@ class Weather(inkycal_module):
return round(miles_per_hour, 1)
@staticmethod
def celsius_to_fahrenheit(celsius:int or float):
def celsius_to_fahrenheit(celsius: int or float):
"""Converts the given temperate from degrees Celsius to Fahrenheit."""
fahrenheit = (celsius * 9 / 5) + 32
return fahrenheit
@@ -180,7 +177,8 @@ class Weather(inkycal_module):
4: '\uf0a3',
5: '\uf0a7',
6: '\uf0aa',
7: '\uf0ae'}[int(index) & 7]
7: '\uf0ae'
}[int(index) & 7]
def is_negative(temp):
"""Check if temp is below freezing point of water (0°C/30°F)
@@ -458,8 +456,9 @@ class Weather(inkycal_module):
# Create a list containing time-objects for every 3rd hour of the day
time_range = list(
arrow.Arrow.range('hour',
now.shift(days=days_from_today).floor('day'),now.shift(days=days_from_today).ceil('day')
))[::3]
now.shift(days=days_from_today).floor('day'),
now.shift(days=days_from_today).ceil('day')
))[::3]
# Get forecasts for each time-object
forecasts = [_ for _ in forecast if arrow.get(_["dt"]) in time_range]
@@ -493,7 +492,7 @@ class Weather(inkycal_module):
if dec_temp != 0:
temperature = f"{round(weather['main']['temp'])}°"
else:
temperature = f"{round(weather['main']['temp'],ndigits=dec_temp)}°"
temperature = f"{round(weather['main']['temp'], ndigits=dec_temp)}°"
weather_icon = weather["weather"][0]["icon"]
humidity = str(weather["main"]["humidity"])

View File

@@ -1,6 +1,6 @@
#!python3
"""Inkycal module template"""
import abc
from inkycal.custom import *