diff --git a/generate.py b/generate.py index d41b35c..1882541 100755 --- a/generate.py +++ b/generate.py @@ -23,13 +23,14 @@ def get_both_languages(text): german, english = text return german, english -def generate_text(number_of_lines = 200, language = None): - """ language can be None (both), "en" or "de". +def generate_texts(number_of_lines = 200): + """ language can be "en" or "de". """ local_hidden_data = hidden_data[:] - do_german = not language or language == "de" - do_english = not language or language == "en" - result = "" + result = { + "de": "", + "en": "", + } for i in range(number_of_lines): emissions, _ = network.choose() german = "" @@ -38,14 +39,14 @@ def generate_text(number_of_lines = 200, language = None): ger, eng = get_both_languages(emission) german += ger english += eng - if do_german: result += german + "\n" - if do_english: result += english + "\n" + 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) - ger, eng = get_both_languages(hidden_line) - if do_german: result += german + "\n" - if do_english: result += english + "\n" + german, english = get_both_languages(hidden_line) + result["de"] += german + "\n" + result["en"] += english + "\n" return result def read_template(filename = "./template.html"): @@ -58,9 +59,10 @@ def write_index(text, filename = "./deploy/index.html"): def main(): template = read_template() + texts = generate_texts() for language in ["de", "en"]: - generated = generate_text(language = language) - generated = resolve_language(greeting, language) + "\n" + generated + generated = resolve_language(greeting, language) + "\n" + generated += resolve_language(texts, language) text = template.replace("", generated) write_index(text, filename = f"./deploy/{language}/index.html")