Skip to content

Commit

Permalink
improve article boilerplate helper
Browse files Browse the repository at this point in the history
  • Loading branch information
tmck-code committed Dec 10, 2024
1 parent 2ebeef8 commit fffe2a0
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions create_article.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python3

import os, sys
import datetime
from argparse import ArgumentParser
import datetime
import os, sys

# parse the command line arguments
parser = ArgumentParser()
Expand Down Expand Up @@ -38,29 +38,29 @@

# add a readme entry that links to the article
# - create the markdown for the readme
entry = [
f'### [{timestamp} {args.title}]({fpath})',
'',
f'> _{args.description}_',
'',
]
# - read in the whole readme
with open('README.md', 'r') as istream:
lines = istream.read().split('\n')
entry = f'''
### [{timestamp} {args.title}]({fpath})
print(lines)
# - find the first existing link - will be the first ### after the ---
new_readme = []
for i, line in enumerate(map(str.strip, lines)):
if line == '---':
print('!!!!!!!!!')
new_readme = lines[:i+2] + entry + lines[i+2:]
break
> _{args.description}_
'''

print('created readme entry:\n', new_readme)
# - read in the whole readme
with open('README.md', 'r') as istream:
header, articles = istream.read().split('---\n', 1)

with open('README.md', 'w') as ostream:
print('\n'.join(new_readme), file=ostream)
print('---\n'.join([header, entry+articles]), file=ostream, end='')

print(f'checking out to branch: {slug}')
os.system(f'git checkout -b {slug}')

os.system(f'git add {fpath} README.md')
os.system(f'git diff --cached')
os.system('git status')
choice = input('looks good? [y/n]: ')
if choice == 'y':
os.system(f'git commit -m "add article: {args.title}"')
os.system('git push')
else:
print('aborting')
sys.exit(1)

0 comments on commit fffe2a0

Please sign in to comment.