from base64 import b64encode from datetime import timedelta def _convert_to_textstring(lst): return '\n'.join(lst) def get_html_table_title(parameters): title = get_print_title_str(parameters) return f'

{title}

\n' def get_html_text(text): return f'

{text}

\n' def get_html_header(refresh_rate=10): header = ['', '', '', ' ', ' ', '', f'', '', '', ''] header = _convert_to_textstring(header) return header def get_mail_html_header(): header = ['', '', '', ''] header = _convert_to_textstring(header) return header def init_html_table(): return '\n' def finish_html_table(): return '
\n' def html_footer(): footer = ['', '\n'] footer = _convert_to_textstring(footer) return footer def add_html_image(img_data, img_format='png'): return f"""
\n""" def get_html_link(text, link): return f' {text} ' def get_html_row(items, html_key='td'): row_string = '' default_space = ' ' row_string += default_space + '\n' for item in items: text = item.get('text') if item.get('bold'): text = '' + text + '' if item.get('italic'): text = '' + text + '' tooltip = item.get('tooltip') color = item.get('color') # check for black background of headers (shouldnt happen anymore) color = '#e6e6e6' if color == '#000000' else color hyperlink = item.get('hyperlink') text_str = get_html_link(text, hyperlink) if hyperlink else text html_class = item.get('html_class') class_str = f' class="{html_class}"' if html_class else '' row_string += 2 * default_space + f'<{html_key}{class_str} bgcolor="{color}" title="{tooltip}"> {text_str}'\ + f'\n' row_string += default_space + '\n' return row_string def get_print_title_str(parameters): timespan = parameters.get('timespan') * 24 * 3600 tdelta_str = str(timedelta(seconds=int(timespan))).replace(', 0:00:00', '') return f'Analysis table of router quality within the last {tdelta_str}'