diff options
author | Starfall <us@starfall.systems> | 2021-10-23 13:30:40 -0500 |
---|---|---|
committer | Starfall <us@starfall.systems> | 2023-12-05 10:00:35 -0600 |
commit | 6fdbf1b748a013b49c228658bb05893e1f01e359 (patch) | |
tree | 1e6fb4d0873705f72610e8a18e7c2cb8bed6c798 /strike.py | |
parent | 2eb81abb648d497b8b9e497ec00d58a893f3727e (diff) |
strike: implement meta[title] and meta[data] from file information
Diffstat (limited to 'strike.py')
-rwxr-xr-x | strike.py | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/strike.py b/strike.py index f3ae173..b417bf1 100755 --- a/strike.py +++ b/strike.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 from os import listdir, mkdir, path from sys import exit +from time import gmtime, strftime from argparse import ArgumentParser from configparser import ConfigParser @@ -23,8 +24,20 @@ def read_config(location): basedir = path.dirname(path.abspath(location[0])) return basedir, parser -def get_output(content, template="{content}"): - return template.format(content = content) +def handle_file(location): + metadata = dict( + title = '.'.join(path.basename(location).split('.')[:-1]), + date = strftime('%a, %d %b %Y %H:%M:%S GMT', gmtime(path.getmtime(location))) + ) + with open(location, 'r') as fin: + file_contents = fin.read() + return file_contents, metadata + +def apply_template(content, metadata, template="{content}"): + return template.format( + content = content, + meta = metadata + ) def main(): args = handle_args() @@ -44,9 +57,8 @@ def main(): for file in listdir(input_dir): if file in exclusions: continue - with open(path.join(input_dir, file), 'r') as fin: - file_contents = fin.read() - output = get_output(file_contents, template) + file_contents, metadata = handle_file(path.join(input_dir, file)) + output = apply_template(file_contents, metadata, template) with open(path.join(output_dir, file), 'w') as fout: fout.write(output) |