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

Format journal_entry.py

parent 9a95cc5c
No related branches found
No related tags found
No related merge requests found
...@@ -30,8 +30,7 @@ def main(): ...@@ -30,8 +30,7 @@ def main():
os.system("git pull") os.system("git pull")
update(new_date) update(new_date)
os.system("git add .") os.system("git add .")
os.system( os.system(f"git commit -m 'Create journal entry for {new_date}'")
f"git commit -m 'Create journal entry for {new_date}'")
os.system("git push") os.system("git push")
...@@ -42,11 +41,7 @@ def update(new_date): ...@@ -42,11 +41,7 @@ def update(new_date):
previous = glob.glob("./journal/2*")[-1] previous = glob.glob("./journal/2*")[-1]
with open(previous, "r") as file: with open(previous, "r") as file:
lines = file.readlines() lines = file.readlines()
lines[2] = re.sub( lines[2] = re.sub(r"next", r"[next](" + f"journal/{new_date}" + ")", lines[2])
r'next',
r'[next](' + f'journal/{new_date}' + ')',
lines[2]
)
# Modify previous entry # Modify previous entry
with open(previous, "w") as file: with open(previous, "w") as file:
...@@ -57,11 +52,9 @@ def update(new_date): ...@@ -57,11 +52,9 @@ def update(new_date):
# Extract upcoming and long-term tasks from previous # Extract upcoming and long-term tasks from previous
upcoming = lines.index("## Upcoming Tasks\n") upcoming = lines.index("## Upcoming Tasks\n")
long_term = lines.index("## Long-term Tasks\n") long_term = lines.index("## Long-term Tasks\n")
create_entry(previous, create_entry(
lines[upcoming+1:long_term-1], previous, lines[upcoming + 1 : long_term - 1], lines[long_term + 1 :], new_date
lines[long_term+1:], )
new_date
)
# Modify MoC # Modify MoC
with open("./journal/map-of-contents.md", "a") as moc: with open("./journal/map-of-contents.md", "a") as moc:
...@@ -71,8 +64,10 @@ def update(new_date): ...@@ -71,8 +64,10 @@ def update(new_date):
# Modify sidebar # Modify sidebar
os.system("head -n -1 ./_sidebar.md > temp.md; mv temp.md ./_sidebar.md") os.system("head -n -1 ./_sidebar.md > temp.md; mv temp.md ./_sidebar.md")
with open("./_sidebar.md", "a") as file: with open("./_sidebar.md", "a") as file:
file.write("[View all pages](https://gitlab1.ptb.de/graefl01/thesis/-/wikis/pages) " file.write(
f"– [Journal](journal/{new_date})\n") "[View all pages](https://gitlab1.ptb.de/graefl01/thesis/-/wikis/pages) "
f"– [Journal](journal/{new_date})\n"
)
print("[INFO] Updated sidebar") print("[INFO] Updated sidebar")
...@@ -81,19 +76,20 @@ def create_entry(previous, prev_tasks, long_term, day): ...@@ -81,19 +76,20 @@ def create_entry(previous, prev_tasks, long_term, day):
week = day.strftime("%W") week = day.strftime("%W")
print(previous) print(previous)
lines = [f"# {day} Journal\n\n", lines = [
f"[previous]({previous[2:-3]}) – {weekday}, week {week} – next\n\n", f"# {day} Journal\n\n",
"## Tasks\n", f"[previous]({previous[2:-3]}) – {weekday}, week {week} – next\n\n",
] "## Tasks\n",
]
lines.extend(prev_tasks) lines.extend(prev_tasks)
lines.extend(("\n", "## Upcoming Tasks\n\n", "- [ ]\n\n")) lines.extend(("\n", "## Upcoming Tasks\n\n", "- [ ]\n\n"))
lines.append("## Long-term Tasks\n") lines.append("## Long-term Tasks\n")
lines.extend(long_term) lines.extend(long_term)
with open(f"./journal/{day}.md", 'w') as file: with open(f"./journal/{day}.md", "w") as file:
file.writelines(lines) file.writelines(lines)
print(f"[INFO] Created entry: {day}") print(f"[INFO] Created entry: {day}")
if __name__ == '__main__': if __name__ == "__main__":
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