From 98f2902f6e880c756eff5046c0ee9bfaf889c102 Mon Sep 17 00:00:00 2001 From: Starfall Date: Thu, 21 Oct 2021 19:57:02 -0500 Subject: strike: simple example of fstring template --- strike.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 strike.py (limited to 'strike.py') diff --git a/strike.py b/strike.py new file mode 100755 index 0000000..3ca1e19 --- /dev/null +++ b/strike.py @@ -0,0 +1,29 @@ +#!/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 main(): + src = 'blog' + dest = 'output' + + 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) + +if __name__ == '__main__': + exit(main()) -- cgit