From 2028e9fceb6222a9d8f21959792584e8ceeb040c Mon Sep 17 00:00:00 2001 From: Starfall Date: Thu, 21 Oct 2021 20:03:33 -0500 Subject: strike: move template from fstring to file --- strike.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'strike.py') diff --git a/strike.py b/strike.py index 3ca1e19..e3e5e52 100755 --- a/strike.py +++ b/strike.py @@ -1,29 +1,26 @@ #!/usr/bin/env python3 from os import listdir, mkdir from sys import exit -from inspect import cleandoc -def get_output(content): - return cleandoc(f''' - i am a template - with some stuff, - {content}, - and some more stuff - ''') +def get_output(content, template="{content}"): + return template.format(content = content) def main(): src = 'blog' dest = 'output' + template = 'template' try: mkdir(dest) except FileExistsError: pass - for file in listdir(src): - with open(src + '/' + file, 'r') as fin: - file_contents = fin.read() - output = get_output(file_contents) - with open(dest + '/' + file, 'w') as fout: - fout.write(output) + with open(template) as t: + template_contents = t.read() + for file in listdir(src): + with open(src + '/' + file, 'r') as fin: + file_contents = fin.read() + output = get_output(file_contents, template=template_contents) + with open(dest + '/' + file, 'w') as fout: + fout.write(output) if __name__ == '__main__': exit(main()) -- cgit