From 117dff248684ca615e09538134678c73541ab078 Mon Sep 17 00:00:00 2001 From: Thor77 Date: Fri, 18 Nov 2016 22:11:14 +0100 Subject: [PATCH] Use TemplateStream.dump for writing template instead of manually opening a file and writing to it --- tsstats/template.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tsstats/template.py b/tsstats/template.py index 965da63..c53c881 100644 --- a/tsstats/template.py +++ b/tsstats/template.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- import logging -from codecs import open from datetime import datetime from os.path import dirname, join @@ -71,8 +70,8 @@ def render_template(clients, output, title='TeamspeakStats', template_env.filters['frmttime'] = frmttime template = template_env.get_template(template) logger.debug('Rendering template %s', template) - with open(output, 'w', encoding='utf-8') as f: - f.write(template.render(title=title, objs=objs, - debug=logger.level <= logging.DEBUG, - creation_time=datetime.utcnow())) - logger.debug('Wrote rendered template to %s', output) + template.stream(title=title, objs=objs, + debug=logger.level <= logging.DEBUG, + creation_time=datetime.utcnow())\ + .dump(output, encoding='utf-8') + logger.debug('Wrote rendered template to %s', output)