from datetime import timedelta def write_html_table_title(fobj, parameters): title = get_print_title_str(parameters) fobj.write(f'

{title}

\n') def write_html_text(fobj, text): fobj.write(f'

{text}

\n') def write_html_header(fobj, refresh_rate=10): header = ['', '', '', ' ', ' ', '', f'', '', '', ''] for item in header: fobj.write(item + '\n') def init_html_table(fobj): fobj.write('\n') def finish_html_table(fobj): fobj.write('
\n') def write_html_footer(fobj): footer = ['', ''] for item in footer: fobj.write(item + '\n') def write_html_row(fobj, items, html_key='td'): default_space = ' ' fobj.write(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') image_str = f'' if hyperlink else '' html_class = item.get('html_class') class_str = f' class="{html_class}"' if html_class else '' fobj.write(2 * default_space + f'<{html_key}{class_str} bgcolor="{color}" title="{tooltip}"> {image_str}' + text + f'\n') fobj.write(default_space + '\n') 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}'