From 992d917c905a04c6e4c077f2e853de0a84903077 Mon Sep 17 00:00:00 2001 From: Flancian <0@flancia.org> Date: Wed, 7 Oct 2020 14:09:08 +0200 Subject: [PATCH] tools/addheader.py: hacky script to add markdown headers where missing, so notes make it to the markdown graph. --- tools/addheader.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 tools/addheader.py diff --git a/tools/addheader.py b/tools/addheader.py new file mode 100755 index 000000000..fb502e730 --- /dev/null +++ b/tools/addheader.py @@ -0,0 +1,24 @@ +#!/usr/bin/python3 +# not proud of this but it works (tm). +import pathlib +import titlecase + +for filename in pathlib.Path('.').glob('**/*.md'): + f = open(filename, 'r') + f_rw = open(filename, 'w') + print('file: %s' % filename) + lines = f.readlines() + if lines: + if lines[0].startswith('#'): + print(filename, 'has a header') + print('---') + else: + sanitized_filename = str(filename).replace('-', ' ') + sanitized_filename = sanitized_filename.replace('.md', '') + sanitized_filename = sanitized_filename.replace('journal/', '') + header = '# ' + titlecase.titlecase(sanitized_filename) + '\n' + print('adding header:', header) + lines.insert(0, header) + # uncomment when this actually works. + # f_rw.writelines(lines) + print('---')