#!/usr/bin/env python3 from os import listdir, mkdir from sys import exit from argparse import ArgumentParser def handle_args(): parser = 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') return parser.parse_args() def get_output(content, template="{content}"): return template.format(content = content) def main(): args = handle_args() try: mkdir(args.output) except FileExistsError: pass with open(args.template) as t: template_contents = t.read() for file in listdir(args.input): with open(args.input + '/' + file, 'r') as fin: file_contents = fin.read() output = get_output(file_contents, template=template_contents) with open(args.output + '/' + file, 'w') as fout: fout.write(output) if __name__ == '__main__': exit(main())