From 79f1fd9eed6f427294287b752153f641ad648e80 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Sun, 19 Jul 2020 15:04:29 +0300 Subject: [PATCH] write output in files --- gen_formula.py | 6 ++++-- templates/wins_black_formula.jinja2 | 8 +++----- templates/wins_formula.jinja2 | 8 +++----- templates/wins_red_formula.jinja2 | 8 +++----- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/gen_formula.py b/gen_formula.py index 8e996da..638edaf 100644 --- a/gen_formula.py +++ b/gen_formula.py @@ -50,7 +50,10 @@ def render_template(name, template): 'fixed_row': 3, 'columns': [c for c in generate_columns()] } - print(template.render(vals)) + filename = os.path.join(os.path.dirname(os.path.dirname(__file__)),'output') + filename = os.path.join(filename, f'{name}.txt') + with open(filename, 'w', encoding='utf8', newline='') as f: + f.write(template.render(vals)) def init_templates(): @@ -67,7 +70,6 @@ def init_templates(): def main(): templates = init_templates() for template in templates.items(): - print(template[0], template[1]) render_template(template[0], template[1]) diff --git a/templates/wins_black_formula.jinja2 b/templates/wins_black_formula.jinja2 index a864a9c..efad4fa 100644 --- a/templates/wins_black_formula.jinja2 +++ b/templates/wins_black_formula.jinja2 @@ -1,6 +1,4 @@ -{% extends 'base.jinja2' %} -{% block conditions %} -{% for column in columns %} -IF(AND({{column}}{{row_num}}={{column}}${{fixed_row}};{{column}}${{fixed_row}}="Ч");1;0); -{% endfor %} +{% extends 'base.jinja2' %}{% block conditions %} +{% for column in columns %}IF(AND({{column}}{{row_num}}={{column}}${{fixed_row}};{{column}}${{fixed_row}}="Ч");1;0); +{% endfor %} {% endblock %} \ No newline at end of file diff --git a/templates/wins_formula.jinja2 b/templates/wins_formula.jinja2 index b777068..dcf9733 100644 --- a/templates/wins_formula.jinja2 +++ b/templates/wins_formula.jinja2 @@ -1,6 +1,4 @@ -{% extends 'base.jinja2' %} -{% block conditions %} -{% for column in columns %} -IF({{column}}{{row_num}}={{column}}${{fixed_row}};1;0); -{% endfor %} +{% extends 'base.jinja2' %}{% block conditions %} +{% for column in columns %}IF({{column}}{{row_num}}={{column}}${{fixed_row}};1;0); +{% endfor %} {% endblock %} \ No newline at end of file diff --git a/templates/wins_red_formula.jinja2 b/templates/wins_red_formula.jinja2 index 37b8061..d7c5a98 100644 --- a/templates/wins_red_formula.jinja2 +++ b/templates/wins_red_formula.jinja2 @@ -1,6 +1,4 @@ -{% extends 'base.jinja2' %} -{% block conditions %} -{% for column in columns %} -IF(AND({{column}}{{row_num}}={{column}}${{fixed_row}};{{column}}${{fixed_row}}="К");1;0); -{% endfor %} +{% extends 'base.jinja2' %}{% block conditions %} +{% for column in columns %}IF(AND({{column}}{{row_num}}={{column}}${{fixed_row}};{{column}}${{fixed_row}}="К");1;0); +{% endfor %} {% endblock %} \ No newline at end of file