From 03f93dbcfc00b808f998cd09fac21d0dbe4246ec Mon Sep 17 00:00:00 2001 From: Thor77 Date: Fri, 4 Sep 2015 21:58:42 +0200 Subject: [PATCH] add frmttime-filter to jinja-env --- tsstats.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tsstats.py b/tsstats.py index f2b719c..eded50b 100755 --- a/tsstats.py +++ b/tsstats.py @@ -8,6 +8,7 @@ from os import sep import configparser from sys import argv from time import mktime +from time import strftime, localtime from os.path import exists from jinja2 import Environment, FileSystemLoader @@ -236,7 +237,12 @@ def render_template(clients, output, template_name='template.html', # render template_loader = FileSystemLoader(abspath) - template = Environment(loader=template_loader).get_template(template_name) + template_env = Environment(loader=template_loader) + + def frmttime(timestamp): + return strftime('%x %X', localtime(int(timestamp))) + template_env.filters['frmttime'] = frmttime + template = template_env.get_template(template_name) with open(output, 'w') as f: f.write(template.render(title=title, objs=objs, debug=debug))