Wrote documentation for every func/class in .py

This commit is contained in:
Kiryl
2021-12-10 10:53:40 +03:00
parent ef3502cd0a
commit 4b1109e6b4
13 changed files with 198 additions and 172 deletions

View File

@@ -6,6 +6,7 @@ from webcolors import html4_hex_to_names, hex_to_rgb, rgb_to_name, rgb_percent_t
def closest_colour_rgb(requested_color):
""" Function finds closes colour rgb """
min_colours = {}
for key, name in html4_hex_to_names.items():
r_c, g_c, b_c = hex_to_rgb(key)
@@ -18,6 +19,7 @@ def closest_colour_rgb(requested_color):
def rgb2color_name(color):
""" Transform rgb -> color name """
try:
closest_name = actual_name = rgb_to_name(color, 'html4')
except ValueError:
@@ -30,6 +32,7 @@ def rgb2color_name(color):
def hex2color_name(color):
""" Transform hex -> color name """
try:
color = hex_to_rgb(color)
except ValueError:
@@ -47,6 +50,7 @@ def hex2color_name(color):
def str2closest_html_color_name(s: str):
""" Transform str -> closest color name """
if 'rgb' in s:
rgb_str = 'rgba' if ('rgba' in s) else 'rgb'
s = s.replace(rgb_str, '').replace('(', '').replace(')', '')
@@ -80,6 +84,7 @@ def str2closest_html_color_name(s: str):
def rgba2rgb(r, g, b, alpha):
""" Transform rgba -> rgb """
r_background, g_background, b_background = 255, 255, 255
r_new = int((1 - alpha) * r_background + alpha * r)
g_new = int((1 - alpha) * g_background + alpha * g)
@@ -88,6 +93,7 @@ def rgba2rgb(r, g, b, alpha):
def str2hex(s: str):
""" Transform str -> hex """
if '#' in s and (len(s) <= 7):
return s.lower()

View File

@@ -3,6 +3,7 @@ import logging
class ColoredFormatter(logging.Formatter):
""" Class to prettify logger and command line output """
MAPPING = {
'DEBUG': 37, # white
'INFO': 36, # cyan
@@ -61,9 +62,7 @@ class BookLogger:
self.logger.log(msg=message, level=logging_level, stacklevel=2)
def log_error_to_main_log(self, message=''):
"""
Method for logging error to main log file.
"""
""" Method for logging error to main log file. """
if self.main_logger:
if not message:
message = f'Error in book conversion. Check log file.'
@@ -71,6 +70,8 @@ class BookLogger:
class BookStatusWrapper:
"""Class sets/updates statuses of Converter on Platform"""
def __init__(self, access, logger_object, book_id=0):
self.access = access
self.logger_object = logger_object