Files
garden/util/fix-journals.py
T
GitJournal 5906265bd5 Added Note
2020-12-02 22:10:58 +01:00

21 lines
677 B
Python

#!/usr/bin/python3
# Run this from the journal directory.
import pathlib
import subprocess
import argparse
import dateparser
parser = argparse.ArgumentParser()
parser.add_argument('--run', action='store_true', help='whether to actually run potentially destructive commands')
args = parser.parse_args()
for filename in pathlib.Path('.').glob('*.md'):
filename = str(filename)
print(filename)
new_filename = dateparser.parse(filename.replace('.md', '')).date().isoformat()
if filename != new_filename:
command = ['git', 'mv', str(filename), new_filename]
print('would run: %s' % command)
if args.run:
subprocess.run(command)