feat: add python scripts

This commit is contained in:
georg.sinn-schirwitz
2024-11-03 12:45:38 +01:00
parent 4772c708f1
commit 646194555c
3 changed files with 169 additions and 0 deletions

64
main.py Normal file
View File

@@ -0,0 +1,64 @@
"""Python application main file for the repository
In this file all python code is referenced and executed that is included in this courses repository.
The main file is used to run the code and to test the functionality of the code.
Functionality of the code is loaded from modules found in folder /src.
"""
import os
import sys
from src import markdown_to_html
from src import file_handler
def main():
"""Main function of the courses module.
This function is the entry point for the courses module.
The function loads the files from the /courses folder and sorts them by file type.
Markdown files are converted to html files and saved in the /html folder.
"""
# Load markdown files from /courses folder
course_files = file_handler.load_files("courses")
markdown_files = file_handler.sort_files(course_files, "md")
html_output_files = file_handler.sort_files(course_files, "html")
# check /html folder
if os.path.exists("html"):
# load html files from /html folder
html_files = file_handler.load_files("html")
# extend converted_files with html files
html_output_files.extend(html_files)
else:
# create /html folder
os.makedirs("html")
for file in html_output_files:
print(f"HTML file: {file}")
name = os.path.splitext(os.path.basename(file))[0]
print(f"Name: {name}")
# move to /html folder
dst_file = f"html/{os.path.basename(file)}"
if not os.path.exists(dst_file):
os.rename(file, dst_file)
print(f"Moved file to /html folder: {dst_file}")
else:
print(f"File already exists in /html folder: {dst_file}")
# get course markdown file name
course_file = f"courses\\{name}.md"
# remove markdown file from list markdown_files
if course_file in markdown_files:
markdown_files.remove(course_file)
print(f"Removed markdown file from list: {course_file}")
# Convert remaining markdown files to html files
markdown_to_html.convert_markdown_files(markdown_files)
if __name__ == "__main__":
main()