Skip to content
Snippets Groups Projects
Commit 10ef92fc authored by Jasper Clemens Gräflich's avatar Jasper Clemens Gräflich
Browse files

Add script for creating new journal pages in wiki

parent 4e778290
No related branches found
No related tags found
No related merge requests found
Pipeline #86537 failed
"""Utility tool to add a new Journal entry to the wiki."""
import glob
import os
import re
from datetime import date, datetime
def main():
# The wikifolder for `<repo>` should be located in `../<repo>.wiki`.
reponame = os.path.basename(os.getcwd())
wikifolder = "../" + reponame + ".wiki"
os.chdir(wikifolder)
os.system("git pull")
update()
os.system("git add .")
os.system(
f"git commit -m 'Create journal entry for {date.today()}'")
def update():
"""Update previous entry, MoC, and _sidebar, and create new entry."""
# Read previous entry
previous = glob.glob("./journal/2*")[-1]
with open(previous, "r") as file:
lines = file.readlines()
lines[2] = re.sub(
r'next',
r'[next](' + f'journal/{date.today()}' + ')',
lines[2]
)
# Modify previous entry
with open(previous, "w") as file:
file.writelines(lines)
# Create new entry
create_entry(previous, lines[lines.index("## Future Tasks\n")+1:])
# Modify MoC
with open("./journal/map-of-contents.md", "a") as moc:
moc.write(f"[{date.today()}](journal/{date.today()})\n")
# Modify sidebar
os.system("head -n -1 ./_sidebar.md > temp.md; mv temp.md ./_sidebar.md")
with open("./_sidebar.md", "a") as file:
file.write("[View all pages](https://gitlab1.ptb.de/graefl01/thesis/-/wikis/pages) "
f"– [Journal](journal/{date.today()})\n")
def create_entry(previous, prev_tasks, day=None):
if day == None:
day = date.today()
weekday = day.strftime("%A")
week = day.strftime("%W")
print(previous)
lines = [f"# {day} Journal\n\n",
f"[previous]({previous[2:-3]}) – {weekday}, week {week} – next\n\n",
"## Tasks\n",
]
lines.extend(prev_tasks)
lines.extend(("\n", "## Future Tasks\n\n", "- [ ]\n\n"))
with open(f"./journal/{day}.md", 'w') as file:
file.writelines(lines)
if __name__ == '__main__':
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment