about summary refs log tree commit diff
path: root/strike.py
blob: dfcb2ed33943adbb6029ac77672c3b267165acf3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/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())