Optionally Pendulum.diff_for_humans instead of frmttime
for relative last seen time (default) * introduce --lastseenabsolute * introduce tsstats.template.render_servers(lastseen_relative=True)
This commit is contained in:
parent
65a8379261
commit
edff1e956d
|
@ -64,6 +64,11 @@ def cli():
|
||||||
'-otth', '--onlinetimethreshold',
|
'-otth', '--onlinetimethreshold',
|
||||||
type=int, help='threshold for displaying onlinetime (in seconds)'
|
type=int, help='threshold for displaying onlinetime (in seconds)'
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'-lsa', '--lastseenabsolute',
|
||||||
|
help='render last seen timestamp absolute (instead of relative)',
|
||||||
|
action='store_false', dest='lastseenrelative'
|
||||||
|
)
|
||||||
options = parser.parse_args()
|
options = parser.parse_args()
|
||||||
if 'config' in options:
|
if 'config' in options:
|
||||||
configuration = config.load(options.config)
|
configuration = config.load(options.config)
|
||||||
|
@ -115,7 +120,11 @@ def main(configuration):
|
||||||
template=configuration.get('General', 'template'),
|
template=configuration.get('General', 'template'),
|
||||||
datetime_fmt=configuration.get('General', 'datetimeformat'),
|
datetime_fmt=configuration.get('General', 'datetimeformat'),
|
||||||
onlinetime_threshold=int(configuration.get(
|
onlinetime_threshold=int(configuration.get(
|
||||||
'General', 'onlinetimethreshold'))
|
'General', 'onlinetimethreshold'
|
||||||
|
)),
|
||||||
|
lastseen_relative=configuration.getboolean(
|
||||||
|
'General', 'lastseenrelative'
|
||||||
|
)
|
||||||
)
|
)
|
||||||
logger.info('Finished after %s seconds', time() - start_time)
|
logger.info('Finished after %s seconds', time() - start_time)
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,8 @@ DEFAULT_CONFIG = {
|
||||||
'onlinedc': True,
|
'onlinedc': True,
|
||||||
'template': 'index.jinja2',
|
'template': 'index.jinja2',
|
||||||
'datetimeformat': '%x %X %Z',
|
'datetimeformat': '%x %X %Z',
|
||||||
'onlinetimethreshold': -1
|
'onlinetimethreshold': -1,
|
||||||
|
'lastseenrelative': True
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ def prepare_clients(clients, onlinetime_threshold=-1):
|
||||||
|
|
||||||
def render_servers(servers, output, title='TeamspeakStats',
|
def render_servers(servers, output, title='TeamspeakStats',
|
||||||
template='index.jinja2', datetime_fmt='%x %X %Z',
|
template='index.jinja2', datetime_fmt='%x %X %Z',
|
||||||
onlinetime_threshold=-1):
|
onlinetime_threshold=-1, lastseen_relative=True):
|
||||||
'''
|
'''
|
||||||
Render `servers`
|
Render `servers`
|
||||||
|
|
||||||
|
@ -70,6 +70,7 @@ def render_servers(servers, output, title='TeamspeakStats',
|
||||||
:param template_path: path to template-file
|
:param template_path: path to template-file
|
||||||
:param datetime_fmt: custom datetime-format
|
:param datetime_fmt: custom datetime-format
|
||||||
:param onlinetime_threshold: threshold for clients onlinetime
|
:param onlinetime_threshold: threshold for clients onlinetime
|
||||||
|
:param lastseen_relative: render last seen timestamp relative
|
||||||
|
|
||||||
|
|
||||||
:type servers: [tsstats.log.Server]
|
:type servers: [tsstats.log.Server]
|
||||||
|
@ -79,6 +80,7 @@ def render_servers(servers, output, title='TeamspeakStats',
|
||||||
:type template_path: str
|
:type template_path: str
|
||||||
:type datetime_fmt: str
|
:type datetime_fmt: str
|
||||||
:type onlinetime_threshold: int
|
:type onlinetime_threshold: int
|
||||||
|
:type lastseen_relative: bool
|
||||||
'''
|
'''
|
||||||
# preparse servers
|
# preparse servers
|
||||||
prepared_servers = [
|
prepared_servers = [
|
||||||
|
@ -98,7 +100,14 @@ def render_servers(servers, output, title='TeamspeakStats',
|
||||||
formatted = timestamp.strftime(datetime_fmt)
|
formatted = timestamp.strftime(datetime_fmt)
|
||||||
logger.debug('Formatting timestamp %s -> %s', timestamp, formatted)
|
logger.debug('Formatting timestamp %s -> %s', timestamp, formatted)
|
||||||
return formatted
|
return formatted
|
||||||
|
|
||||||
|
def lastseen(timestamp):
|
||||||
|
if lastseen_relative:
|
||||||
|
return timestamp.diff_for_humans()
|
||||||
|
else:
|
||||||
|
return frmttime(timestamp)
|
||||||
template_env.filters['frmttime'] = frmttime
|
template_env.filters['frmttime'] = frmttime
|
||||||
|
template_env.filters['lastseen'] = lastseen
|
||||||
template = template_env.get_template(template)
|
template = template_env.get_template(template)
|
||||||
logger.debug('Rendering template %s', template)
|
logger.debug('Rendering template %s', template)
|
||||||
template.stream(title=title, servers=prepared_servers,
|
template.stream(title=title, servers=prepared_servers,
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
{% set id = [headline_id, client.nick|striptags]|join('.') %}
|
{% set id = [headline_id, client.nick|striptags]|join('.') %}
|
||||||
<li id="{{ id }}" class="list-group-item{{ ' list-group-item-success' if client.connected else loop.cycle('" style="background-color: #eee;', '') }}">
|
<li id="{{ id }}" class="list-group-item{{ ' list-group-item-success' if client.connected else loop.cycle('" style="background-color: #eee;', '') }}">
|
||||||
<span class="hint--right hint--medium--xs" data-hint="{{ client.nick_history|join(', ') }}"><a href="#{{ id }}">{{ client.nick }}{{ " (" + client.identifier + ")" if debug }}</a></span>
|
<span class="hint--right hint--medium--xs" data-hint="{{ client.nick_history|join(', ') }}"><a href="#{{ id }}">{{ client.nick }}{{ " (" + client.identifier + ")" if debug }}</a></span>
|
||||||
<span class="badge"><div{% if not client.connected and headline == 'Onlinetime' %} class="hint--left" data-hint="{{ client.last_seen|frmttime }}"{% endif %}>{{ value }}</div></span>
|
<span class="badge"><div{% if not client.connected and headline == 'Onlinetime' %} class="hint--left" data-hint="{{ client.last_seen|lastseen }}"{% endif %}>{{ value }}</div></span>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
Loading…
Reference in New Issue