#!/usr/bin/python3 from random import randint, random, choice from crime_campus_exam_data import greeting, network, hidden_data def resolve_language(text, language): if isinstance(text, str): return text if isinstance(text, dict): return text[language] german, english = text if language == "de": return german else: return english def get_both_languages(text): if isinstance(text, str): return text, text if isinstance(text, dict): return text["de"], text["en"] german, english = text return german, english def generate_texts(number_of_lines = 200): """ language can be "en" or "de". """ local_hidden_data = hidden_data[:] result = { "de": "", "en": "", } for i in range(number_of_lines): emissions, _ = network.choose() german = "" english = "" for emission in emissions: ger, eng = get_both_languages(emission) german += ger english += eng result["de"] += german + "\n" result["en"] += english + "\n" if random() < len(local_hidden_data) / (number_of_lines - i): index = randint(0, len(local_hidden_data) - 1) hidden_line = local_hidden_data.pop(index) german, english = get_both_languages(hidden_line) result["de"] += german + "\n" result["en"] += english + "\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() texts = generate_texts() for language in ["de", "en"]: generated = resolve_language(greeting, language) + "\n" generated += resolve_language(texts, language) text = template.replace("", generated) write_index(text, filename = f"./deploy/{language}/index.html") if __name__ == "__main__": main()