2022-11-07 17:56:41 +01:00
|
|
|
from datetime import timedelta
|
|
|
|
|
|
|
|
def write_html_table_title(fobj, parameters):
|
|
|
|
title = get_print_title_str(parameters)
|
|
|
|
fobj.write(f'<h3>{title}</h3>\n')
|
|
|
|
|
|
|
|
def write_html_text(fobj, text):
|
|
|
|
fobj.write(f'<p>{text}</p>\n')
|
|
|
|
|
2022-11-08 12:06:00 +01:00
|
|
|
def write_html_header(fobj, refresh_rate=10):
|
2022-11-07 17:56:41 +01:00
|
|
|
header = ['<!DOCTYPE html>',
|
|
|
|
'<html>',
|
2022-11-08 12:06:00 +01:00
|
|
|
f'<meta http-equiv="refresh" content="{refresh_rate}" >',
|
|
|
|
'<meta charset="utf-8">',
|
2022-11-07 17:56:41 +01:00
|
|
|
'<body>']
|
2022-11-08 12:06:00 +01:00
|
|
|
# style = ['<style>',
|
|
|
|
# 'table, th, td {',
|
|
|
|
# 'border:1px solid black;',
|
|
|
|
# '}',
|
|
|
|
# '</style>',]
|
2022-11-07 17:56:41 +01:00
|
|
|
for item in header:
|
|
|
|
fobj.write(item + '\n')
|
|
|
|
|
|
|
|
def init_html_table(fobj):
|
|
|
|
fobj.write('<table style="width:100%">\n')
|
|
|
|
|
|
|
|
def finish_html_table(fobj):
|
|
|
|
fobj.write('</table>\n')
|
|
|
|
|
|
|
|
def write_html_footer(fobj):
|
|
|
|
footer = ['</body>',
|
|
|
|
'</html>']
|
|
|
|
for item in footer:
|
|
|
|
fobj.write(item + '\n')
|
|
|
|
|
|
|
|
def write_html_row(fobj, items, html_key='td'):
|
2022-11-08 12:06:00 +01:00
|
|
|
default_space = ' '
|
|
|
|
fobj.write(default_space + '<tr>\n')
|
2022-11-07 17:56:41 +01:00
|
|
|
for item in items:
|
2022-11-08 16:45:21 +01:00
|
|
|
text = item.get('text')
|
|
|
|
tooltip = item.get('tooltip')
|
|
|
|
color = item.get('color')
|
|
|
|
# check for black background of headers (shouldnt happen anymore)
|
2022-11-07 17:56:41 +01:00
|
|
|
color = '#e6e6e6' if color == '#000000' else color
|
2022-11-15 13:44:19 +01:00
|
|
|
hyperlink = item.get('hyperlink')
|
|
|
|
image_str = f'<a href="{hyperlink}">' if hyperlink else ''
|
2022-11-09 14:32:13 +01:00
|
|
|
fobj.write(2 * default_space + f'<{html_key} bgcolor="{color}" title="{tooltip}"> {image_str}'
|
|
|
|
+ text + f'</{html_key}>\n')
|
2022-11-08 12:06:00 +01:00
|
|
|
fobj.write(default_space + '</tr>\n')
|
2022-11-07 17:56:41 +01:00
|
|
|
|
|
|
|
def get_print_title_str(parameters):
|
|
|
|
timespan = parameters.get('timespan') * 24 * 3600
|
|
|
|
tdelta_str = str(timedelta(seconds=int(timespan)))
|
|
|
|
return f'Analysis table of router quality within the last {tdelta_str}'
|
|
|
|
|