diff --git a/tsstats/__main__.py b/tsstats/__main__.py index 7bbea3e..70b4c8b 100644 --- a/tsstats/__main__.py +++ b/tsstats/__main__.py @@ -64,6 +64,11 @@ def cli(): '-otth', '--onlinetimethreshold', 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() if 'config' in options: configuration = config.load(options.config) @@ -115,7 +120,11 @@ def main(configuration): template=configuration.get('General', 'template'), datetime_fmt=configuration.get('General', 'datetimeformat'), onlinetime_threshold=int(configuration.get( - 'General', 'onlinetimethreshold')) + 'General', 'onlinetimethreshold' + )), + lastseen_relative=configuration.getboolean( + 'General', 'lastseenrelative' + ) ) logger.info('Finished after %s seconds', time() - start_time) diff --git a/tsstats/config.py b/tsstats/config.py index 8ed3a87..74f9478 100644 --- a/tsstats/config.py +++ b/tsstats/config.py @@ -20,7 +20,8 @@ 'onlinedc': True, 'template': 'index.jinja2', 'datetimeformat': '%x %X %Z', - 'onlinetimethreshold': -1 + 'onlinetimethreshold': -1, + 'lastseenrelative': True } } diff --git a/tsstats/template.py b/tsstats/template.py index fd290a4..d28edb9 100644 --- a/tsstats/template.py +++ b/tsstats/template.py @@ -59,7 +59,7 @@ def prepare_clients(clients, onlinetime_threshold=-1): def render_servers(servers, output, title='TeamspeakStats', template='index.jinja2', datetime_fmt='%x %X %Z', - onlinetime_threshold=-1): + onlinetime_threshold=-1, lastseen_relative=True): ''' Render `servers` @@ -70,6 +70,7 @@ def render_servers(servers, output, title='TeamspeakStats', :param template_path: path to template-file :param datetime_fmt: custom datetime-format :param onlinetime_threshold: threshold for clients onlinetime + :param lastseen_relative: render last seen timestamp relative :type servers: [tsstats.log.Server] @@ -79,6 +80,7 @@ def render_servers(servers, output, title='TeamspeakStats', :type template_path: str :type datetime_fmt: str :type onlinetime_threshold: int + :type lastseen_relative: bool ''' # preparse servers prepared_servers = [ @@ -98,7 +100,14 @@ def frmttime(timestamp): formatted = timestamp.strftime(datetime_fmt) logger.debug('Formatting timestamp %s -> %s', timestamp, 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['lastseen'] = lastseen template = template_env.get_template(template) logger.debug('Rendering template %s', template) template.stream(title=title, servers=prepared_servers, diff --git a/tsstats/templates/stats.jinja2 b/tsstats/templates/stats.jinja2 index cb1a470..8a34fcc 100644 --- a/tsstats/templates/stats.jinja2 +++ b/tsstats/templates/stats.jinja2 @@ -14,7 +14,7 @@ {% set id = [headline_id, client.nick|striptags]|join('.') %}
  • {{ client.nick }}{{ " (" + client.identifier + ")" if debug }} - {{ value }} + {{ value }}
  • {% endfor %}