#!/usr/bin/env python3 from os import listdir, mkdir from sys import exit import argparse def get_output(content, template="{content}"): return template.format(content = content) def main(): parser = argparse.ArgumentParser() parser.add_argument('--input', '-i', help='input directory (default "blog")', default='blog') parser.add_argument('--output', '-o', help='output directory (default "output")', default='output') parser.add_argument('--template', '-t', help='template to use (default "template"', default='template') args = parser.parse_args() src = args.input dest = args.output try: mkdir(dest) except FileExistsError: pass template = args.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())