#!/usr/bin/python3 from random import randint, random, choice from choice_network import Choice, FixedText, RandInt, Network def get_names(filename, pad = " "): lines = [] with open(filename) as file: lines = file.read().split("\n") names = [ name + pad for name in lines if len(name) > 1 ] return names greeting = """ Re: AW: Exmatrikulationsgefährdete Studierende --------- Englisch version below. Hallo, Zur angefragten Prüfung gibt es leider noch keine Datenbank, daher hier unsere Notizen aus Prüfungsakten und Personendatenbank. Vielleicht können Sie die ja mit regulären Ausdrücken filtern. Das funktioniert wie normale Text-Suche, nur etwas flexibler: (Erst|Zweit)versuch z.B. würde sowohl 'Erstversuch' als auch 'Zweitversuch' markieren. .+ akzeptiert alle Zeichen, das können Sie vorn anfügen, um im Menü 'List' unten rechts den Anfang der Zeile zu sehen. Viel Spaß === ENGLISCH VERSION === Hi, there is no database for this exam, so we can only send our digitized notes. Maybe you can filter it with regular expressions? They are like normal text-search but more flexible: E.g.: (Erst|Zweit)versuch would select both words: 'Erstversuch' (first attempt) and 'Zweitversuch' (second attempt). .+ will accept any text, you can add it at the start to see the whole line in the menu 'List' (bottom right). """ # fünf Tatverdächtige # Uhrzeiten, siehe Infos von Verantwortlichen # Groß-Klein-Schreibung date = "05.06.2024" hidden_data = [ "Anna Bartel: Zweitversuch nicht bestanden.\n" "Anna Bartel: second attempt not passed.", "Boris Parsch: Zweitversuch nicht bestanden.\n" "Boris Parsch: second attempt not passed.", "Carola Winter: 2. Versuch nicht bestanden.\n" "Carola Winter: 2nd attempt not passed.", "Dennis Meier: 2. Versuch nicht bestanden.\n" "Dennis Meier: 2nd attempt not passed.", "Elisa Menniz: Zweitversuch nicht bestanden.\n" "Elisa Menniz: second attempt not passed.", f"Anna Bartel: Prüfung am {date} um 13:00.\n" f"Anna Bartel: exam on {date}, 13:00.", f"Boris Parsch: Prüfung am {date} um 14:00.\n" f"Boris Parsch: exam on {date}, 14:00.", f"Carola Winter: Prüfung am {date} um 13:30.\n" f"Carola Winter: exam on {date}, 13:30.", f"Dennis Meier: Prüfung am {date} um 10:00.\n" f"Dennis Meier: exam on {date}, 10:00.", f"Elisa Menniz: Prüfung am {date} um 14:30.\n" f"Elisa Menniz: exam on {date}, 14:30.", f"Anna Bartel: blaue Augen.\n" f"Anna Bartel: blue eyes.", f"Boris Parsch: blaue Augen.\n" f"Boris Parsch: blue eyes.", f"Carola Winter: blaue Augen.\n" f"Carola Winter: blue eyes.", f"Dennis Meier: grüne Augen.\n" f"Dennis Meier: green eyes.", f"Elisa Menniz: grüne Augen.\n" f"Elisa Menniz: green eyes.", ] network = Network( start = Choice( student = [""], ), student = Choice( last_name = get_names("vornamen.csv"), ), last_name = Choice( student_mit = get_names("nachnamen.csv", pad = ""), ), student_mit = Choice( hat_den = [""], ), hat_den = Choice( versuch = [": ",], prüfungszeit = [(f": Prüfung am {date} um ", f": exam on {date}, ")], augenfarbe = [": ",], ), augenfarbe = Choice( augen = [ ("grüne ", "green "), ("braune ", "brown "), ("blaue ", "blue "), ], ), augen = FixedText( stop = ("Augen.", "eyes."), ), prüfungszeit = Choice( uhr = [ "09:00", "09:30", "10:00", "10:30", "11:00", "11:30", "12:00", "12:30", "13:00", "13:30", "14:00", "14:30", "15:00", "15:30", ], ), uhr = FixedText( stop = (" Uhr.", "."), ), versuch = Choice( nicht = [ ("Erstversuch ", "first attempt "), ("1. Versuch ", "1st attempt "), ], bestanden = [ ("Erstversuch ", "first attempt "), ("1. Versuch ", "1st attempt "), ("Zweitversuch ", "second attempt "), ("2. Versuch ", "2nd attempt "), ], ), nicht = Choice( bestanden = [ ("nicht ", "not "), "" ], ), bestanden = FixedText( stop = ("bestanden.", "passed."), ), ) def pop_hidden_data(): global hidden_data index = randint(0, len(hidden_data) - 1) return hidden_data.pop(index) def generate_text(number_of_lines = 200): result = "" for i in range(number_of_lines): emissions, _ = network.choose() german = "" english = "" for emission in emissions: match emission: case (ger, eng): german += ger english += eng case both: german += both english += both result += german + "\n" result += english + "\n" if random() < len(hidden_data) / (number_of_lines - i): result += pop_hidden_data() + "\n" return result def read_template(filename = "./template.html"): with open(filename, "r") as file: return file.read() def write_index(text, filename = "./deploy/index.html"): with open(filename, "w") as file: file.write(text) def main(): template = read_template() generated = generate_text() generated = greeting + "\n" + generated text = template.replace("", generated) write_index(text) if __name__ == "__main__": main()