[minor] add html class for mobile (WIP)
This commit is contained in:
parent
6fc1e073c0
commit
19b8df8f7d
18
survBot.py
18
survBot.py
@ -352,7 +352,17 @@ class SurveillanceBot(object):
|
||||
fig.savefig(fnout, dpi=150., bbox_inches='tight')
|
||||
plt.close(fig)
|
||||
|
||||
def write_html_table(self, default_color='#e6e6e6', default_header_color='#999'):
|
||||
def write_html_table(self, default_color='#e6e6e6', default_header_color='#999', hide_keys_mobile=('other')):
|
||||
|
||||
def get_html_class(status=None, check_key=None):
|
||||
""" helper function for html class if a certain condition is fulfilled """
|
||||
html_class = None
|
||||
if status and status.is_active:
|
||||
html_class = 'blink-bg'
|
||||
if check_key in hide_keys_mobile:
|
||||
html_class = 'hidden-mobile'
|
||||
return html_class
|
||||
|
||||
self.check_html_dir()
|
||||
fnout = pjoin(self.outpath_html, 'survBot_out.html')
|
||||
if not fnout:
|
||||
@ -370,7 +380,8 @@ class SurveillanceBot(object):
|
||||
header.insert(-1, key)
|
||||
header_items = [dict(text='Station', color=default_header_color)]
|
||||
for check_key in header:
|
||||
item = dict(text=check_key, color=default_header_color)
|
||||
html_class = get_html_class(check_key=check_key)
|
||||
item = dict(text=check_key, color=default_header_color, html_class=html_class)
|
||||
header_items.append(item)
|
||||
write_html_row(outfile, header_items, html_key='th')
|
||||
|
||||
@ -397,8 +408,9 @@ class SurveillanceBot(object):
|
||||
if not type(message) in [str]:
|
||||
message = str(message) + deg_str
|
||||
|
||||
html_class = get_html_class(status=status, check_key=check_key)
|
||||
item = dict(text=str(message), tooltip=str(detailed_message), color=bg_color,
|
||||
blink=status.is_active)
|
||||
html_class=html_class)
|
||||
elif check_key in self.add_links:
|
||||
value = self.add_links.get(check_key).get('URL')
|
||||
link_text = self.add_links.get(check_key).get('text')
|
||||
|
@ -18,6 +18,9 @@ def write_html_header(fobj, refresh_rate=10):
|
||||
'</head>',
|
||||
f'<meta http-equiv="refresh" content="{refresh_rate}" >',
|
||||
'<meta charset="utf-8">',
|
||||
'<meta name="viewport" content="width=device-width, initial-scale=1">',
|
||||
'<link rel="stylesheet" media="only screen and (max-width: 400px)" href="mobile.css" />',
|
||||
'<link rel="stylesheet" media="only screen and (min-width: 401px)" href="desktop.css" />',
|
||||
'<body>']
|
||||
# style = ['<style>',
|
||||
# 'table, th, td {',
|
||||
@ -58,8 +61,9 @@ def write_html_row(fobj, items, html_key='td'):
|
||||
color = '#e6e6e6' if color == '#000000' else color
|
||||
hyperlink = item.get('hyperlink')
|
||||
image_str = f'<a href="{hyperlink}">' if hyperlink else ''
|
||||
blink_str = f' class="blink-bg"' if item.get('blink') else ''
|
||||
fobj.write(2 * default_space + f'<{html_key}{blink_str} bgcolor="{color}" title="{tooltip}"> {image_str}'
|
||||
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'</{html_key}>\n')
|
||||
fobj.write(default_space + '</tr>\n')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user