4 Commits

Author SHA1 Message Date
f1d25a7809 [bugfix] fixed footer output to produce valid html when using a logo
new parameters in for paramters.yaml file:
  - added parameter logo_alt_text
  - added parameter logo_height
2025-04-03 15:09:08 +02:00
a905386ee8 [bugfix] fixed html output to produce valid html. 2025-04-03 14:25:03 +02:00
a64aeaa5ac [minor] add versioninformation to footer line 2025-04-03 14:23:44 +02:00
206af05f26 Merge branch 'feature/docker' into develop 2025-04-02 18:11:18 +02:00
2 changed files with 24 additions and 14 deletions

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
__version__ = '0.3' __version__ = '0.3.1'
__author__ = ['Marcel Paffrath <marcel.paffrath@rub.de>', 'Kasper D. Fischer <kasper.fischer@rub.de>'] __author__ = ['Marcel Paffrath <marcel.paffrath@rub.de>', 'Kasper D. Fischer <kasper.fischer@rub.de>']
import os import os
@@ -537,11 +537,13 @@ class SurveillanceBot(object):
# write footer with optional logo # write footer with optional logo
logo_file = self.parameters.get('html_logo') logo_file = self.parameters.get('html_logo')
logo_alt_text = self.parameters.get('logo_alt_text')
logo_height = self.parameters.get('logo_height')
if not os.path.isfile(pjoin(self.outpath_html, logo_file)): if not os.path.isfile(pjoin(self.outpath_html, logo_file)):
logging.info(f'Specified file {logo_file} not found.') logging.info(f'Specified file {logo_file} not found.')
logo_file = None logo_file = None
outfile.write(html_footer(footer_logo=logo_file)) outfile.write(html_footer(footer_logo=logo_file, alt_text=logo_alt_text, height=logo_height))
except Exception as e: except Exception as e:
logging.info(f'Could not write HTML table to {fnout}:') logging.info(f'Could not write HTML table to {fnout}:')
@@ -551,7 +553,8 @@ class SurveillanceBot(object):
def update_status_message(self): def update_status_message(self):
timespan = timedelta(seconds=int(self.parameters.get('timespan') * 24 * 3600)) timespan = timedelta(seconds=int(self.parameters.get('timespan') * 24 * 3600))
self.status_message = f'Program starttime (UTC) {self.starttime.strftime("%Y-%m-%d %H:%M:%S")} | ' \ self.status_message = f' Version {__version__} | ' \
f'Program start time (UTC) {self.starttime.strftime("%Y-%m-%d %H:%M:%S")} | ' \
f'Current time (UTC) {UTCDateTime().strftime("%Y-%m-%d %H:%M:%S")} | ' \ f'Current time (UTC) {UTCDateTime().strftime("%Y-%m-%d %H:%M:%S")} | ' \
f'Refresh period: {self.refresh_period}s | ' \ f'Refresh period: {self.refresh_period}s | ' \
f'Showing data of last {timespan}' f'Showing data of last {timespan}'

View File

@@ -17,7 +17,7 @@ def get_html_text(text):
def get_html_header(refresh_rate=10): def get_html_header(refresh_rate=10):
header = ['<!DOCTYPE html>', header = ['<!DOCTYPE html>',
'<html>', '<html lang="en">',
'<head>', '<head>',
' <title>SurvBot status</title>', ' <title>SurvBot status</title>',
' <link rel="stylesheet" media="only screen and (max-width: 400px)" href="mobile.css">', ' <link rel="stylesheet" media="only screen and (max-width: 400px)" href="mobile.css">',
@@ -26,7 +26,7 @@ def get_html_header(refresh_rate=10):
' <meta charset="utf-8">', ' <meta charset="utf-8">',
' <meta name="viewport" content="width=device-width, initial-scale=1">', ' <meta name="viewport" content="width=device-width, initial-scale=1">',
'</head>', '</head>',
'<body>'] '<body>\n']
header = _convert_to_textstring(header) header = _convert_to_textstring(header)
return header return header
@@ -48,14 +48,15 @@ def finish_html_table():
return '</table>\n' return '</table>\n'
def html_footer(footer_logo=None): def html_footer(footer_logo=None, alt_text='Logo', height=30):
footer = ['</body>']
if footer_logo: if footer_logo:
logo_items = [f'<div class="footer">', footer = [f'<div class="footer">',
f' <img style="float: right; padding: 10px;" src="{footer_logo}" height=30px>', f' <img style="float: right; padding: 10px;" src="{footer_logo}" height={height} alt="{alt_text}">',
f'</div>'] f'</div>']
footer += logo_items else:
footer.append('</html>\n') footer = []
footer.append('</body>')
footer.append('</html>')
footer = _convert_to_textstring(footer) footer = _convert_to_textstring(footer)
return footer return footer
@@ -86,8 +87,14 @@ def get_html_row(items, html_key='td'):
text_str = get_html_link(text, hyperlink) if hyperlink else text text_str = get_html_link(text, hyperlink) if hyperlink else text
html_class = item.get('html_class') html_class = item.get('html_class')
class_str = f' class="{html_class}"' if html_class else '' class_str = f' class="{html_class}"' if html_class else ''
row_string += 2 * default_space + f'<{html_key}{class_str} bgcolor="{color}" title="{tooltip}"' \ row_string += 2 * default_space + f'<{html_key}{class_str} '
+ f'style="color:{font_color}">{text_str}</{html_key}>\n' row_string += f'title="{tooltip}" ' if tooltip else ''
row_string += 'style="' if color or font_color else ''
row_string += f'background-color: {color};' if color else 'style="'
row_string += ' ' if font_color else ''
row_string += f'color: {font_color};' if font_color else ''
row_string += '" ' if color or font_color else ''
row_string += f'>{text_str}</{html_key}>\n'
row_string += default_space + '</tr>\n' row_string += default_space + '</tr>\n'
return row_string return row_string