tmp-gitea/scripts/gen.py

40 lines
1 KiB
Python
Raw Normal View History

2022-10-30 14:04:51 +05:30
from datetime import datetime
from dateutil.parser import parse as parse_date
def write_file(title, contents):
title = title.strip()
filename = title.replace(' ', '-').lower()
if "Current status" in title:
date = datetime.now()
else:
date = parse_date(title)
filename += '.md'
with open(f"content/updates/{filename}", "w", encoding='utf-8') as f:
print(f"[*] Writing update {filename}")
f.write("+++\n")
f.write(f"title = '{title}'\n")
f.write(f"date = '{date}'\n")
f.write("+++\n")
f.write(update)
with open("./status.md", "r", encoding='utf-8') as f:
title = None
update = ""
for line in f.readlines():
if line.startswith("###"):
if title:
write_file(title, update)
title = line.removeprefix("### ")
update = ""
else:
if title:
if line.startswith("---"):
break
else:
update += line
write_file(title, update)