Hong-Phuc Bui
2024-09-27 45c96fe258657363ef4ad1a2ae93513ca4139e26
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from mystudy.lecture import Lecture, parse_lecture_line, Lecture2HTMLConverter
from sys import argv
 
 
def read_file_to_lecture(filename: str) -> list[Lecture]:
    lectures = []
    count_line = 0
    try:
        with open(filename, 'r') as file:
            while line := file.readline():
                count_line += 1
                if len(line.strip()) > 0:
                    l = parse_lecture_line(line)
                    lectures.append(l)
        return lectures
    except (IndexError, ValueError):
        print(f"[{count_line}] Dateiformat fehlerbehaftet")
 
 
def start():
    try:
        filename = argv[1]
        lectures = read_file_to_lecture(filename)
        if lectures is not  None:
            converter = Lecture2HTMLConverter()
            html_code = converter.convert(lectures)
            print(html_code)
    except FileNotFoundError:
        print(f"Datei '{filename}' nicht gefunden")