Skip to content

Commit

Permalink
add more flexible template
Browse files Browse the repository at this point in the history
  • Loading branch information
li-xin-yi committed Dec 26, 2019
1 parent 649cb62 commit 201e962
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
19 changes: 16 additions & 3 deletions hkjournalist/journalist.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ def hear(self, config_dict: dict):
newest_config = self.__preprocess(config_dict)
self.report_config.update(newest_config)

def generate_template(self, template_file='./template.md'):
def generate_template(self, template_file='./template.md',title='template',author='Author',append=False):

"""Generate a `md` template according to mappings which previously passed to.
The output template will be structed as each variable on a single slide with variable name as its title
Expand All @@ -123,11 +124,23 @@ def generate_template(self, template_file='./template.md'):
:type template_file: str
:return: None
:rtype: None
:param title: report title
:type title: str
:param author: author name
:type author: str
:param append: If use append mode to add new contents of report
:type append: bool
:return:
"""
if self.template_file:
if self.template_file and not append:
print('warning: template file was specified before and will be overwritten')

self.template_file = template_file
report_text = '% Report template \n% Author\n% {today}\n\n'
if append:
report_text = open(self.template_file).read() + '\n'
else:
report_text = f'% {title} \n% {author} \n% {{today}}\n\n'

for k, v in self.var_type.items():
k_name = '{' + k + '}'
title = f"### {k}\n\n"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="hkjournalist",
version="0.0.3",
version="0.0.4",
author="Xinyi",
author_email="[email protected]",
description="Custom Auto Report Generator for Python Program",
Expand Down

0 comments on commit 201e962

Please sign in to comment.