mirror of
https://github.com/flancian/garden.git
synced 2026-08-08 07:26:21 +00:00
Fix Roam journal entries, plus move tools to util by convention.
This commit is contained in:
Executable
+23
@@ -0,0 +1,23 @@
|
||||
#!/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')
|
||||
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)
|
||||
with open(filename, 'w') as f_rw:
|
||||
f_rw.writelines(lines)
|
||||
print('---')
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/python3
|
||||
import pathlib
|
||||
import subprocess
|
||||
import argparse
|
||||
|
||||
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'):
|
||||
new_filename = str(filename).lower().replace(' ', '-')
|
||||
command = ['git', 'mv', str(filename), new_filename]
|
||||
print('would run: %s' % command)
|
||||
if args.run:
|
||||
subprocess.run(command)
|
||||
Executable
+20
@@ -0,0 +1,20 @@
|
||||
#!/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)
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/python3
|
||||
import pathlib
|
||||
import titlecase
|
||||
|
||||
for filename in pathlib.Path('.').glob('**/*.md'):
|
||||
f = open(filename)
|
||||
print('file: %s' % filename)
|
||||
lines = f.readlines()
|
||||
if lines:
|
||||
if lines[0].startswith('#'):
|
||||
print(filename, 'has a header')
|
||||
else:
|
||||
sanitized_filename = str(filename).replace('-', ' ')
|
||||
sanitized_filename = sanitized_filename.replace('.md', '')
|
||||
sanitized_filename = sanitized_filename.replace('journal/', '')
|
||||
header = '# ' + titlecase.titlecase(sanitized_filename)
|
||||
print('would add header:', header)
|
||||
Reference in New Issue
Block a user