Use TemplateStream.dump for writing template
instead of manually opening a file and writing to it
This commit is contained in:
parent
87e5d697cb
commit
117dff2486
|
@ -1,7 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from codecs import open
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from os.path import dirname, join
|
from os.path import dirname, join
|
||||||
|
|
||||||
|
@ -71,8 +70,8 @@ def render_template(clients, output, title='TeamspeakStats',
|
||||||
template_env.filters['frmttime'] = frmttime
|
template_env.filters['frmttime'] = frmttime
|
||||||
template = template_env.get_template(template)
|
template = template_env.get_template(template)
|
||||||
logger.debug('Rendering template %s', template)
|
logger.debug('Rendering template %s', template)
|
||||||
with open(output, 'w', encoding='utf-8') as f:
|
template.stream(title=title, objs=objs,
|
||||||
f.write(template.render(title=title, objs=objs,
|
debug=logger.level <= logging.DEBUG,
|
||||||
debug=logger.level <= logging.DEBUG,
|
creation_time=datetime.utcnow())\
|
||||||
creation_time=datetime.utcnow()))
|
.dump(output, encoding='utf-8')
|
||||||
logger.debug('Wrote rendered template to %s', output)
|
logger.debug('Wrote rendered template to %s', output)
|
||||||
|
|
Loading…
Reference in New Issue