#!/usr/bin/env python3 from os import listdir, mkdir from sys import exit def get_output(content, template="{content}"): return template.format(content = content) def main(): src = 'blog' dest = 'output' try: mkdir(dest) except FileExistsError: pass template = 'template' 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())