linux_introduction/generate_md.py

39 lines
1.2 KiB
Python
Executable File

#!/usr/bin/python3
import re
INPUT = "readme.md"
OUTPUT = "homework/todo_template.md"
URL = "https://gitea.86thumbs.net/waldek/linux_introduction/src/branch/master/"
if __name__ == "__main__":
with open(INPUT, "r") as fp:
src = []
for line in fp.readlines():
src.append(line)
data = []
for nr, line in zip(range(0, len(src)), src):
stripped = line.strip()
stripped = stripped.replace("*", "")
stripped = stripped.strip()
if "====" in line:
data.append("# {}".format(src[nr - 1]))
if "(./" in stripped:
topic = stripped[stripped.find("[")+1:stripped.find("]")]
url = stripped.replace("(./", "({}".format(URL))
url = re.sub("\[.*\]", "[Link]", url)
url = " * {} to course documentation".format(url)
header = "## {}".format(topic)
notes = "### Student notes:"
data.append(header)
data.append(url)
data.append(notes)
data.append("TODO")
with open(OUTPUT, "w") as fp:
for line in data:
fp.write("{}\n\n".format(line))