From 9fc0620e04430710d0bcc9e9239cbbfe376977de Mon Sep 17 00:00:00 2001 From: tebarius Date: Tue, 22 Jul 2025 19:39:47 +0200 Subject: [PATCH] updated generate-remorse-function --- .dockerignore | 4 +++- .gitignore | 2 ++ app/tools.py | 33 +++++++++++++-------------------- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/.dockerignore b/.dockerignore index 87e463d..a35448d 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,5 @@ **/*.pyc **/*.pyo -**/__pycache__ \ No newline at end of file +**/__pycache__ +**/morse-de.dic +**/t9-de.dic \ No newline at end of file diff --git a/.gitignore b/.gitignore index 7666b19..74bf0ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /app/__pycache__/ /venv/ /.idea/ +/app/data/morse-de.dic +/app/data/t9-de.dic diff --git a/app/tools.py b/app/tools.py index ff4012e..4efb395 100644 --- a/app/tools.py +++ b/app/tools.py @@ -2088,7 +2088,6 @@ def remorse_germandic(): Ausgabe.insert(1.0, ualphabet[eingabetext] + "\n") Ausgabe.insert(1.0, "der eingegebene Morsecode kann für folgendes stehen:\n", "bu") - def remorse_generate_morsede(): alphabet = {'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.', 'F': '..-.', 'G': '--.', 'H': '....', 'I': '..', 'J': '.---', 'K': '-.-', 'L': '.-..', 'M': '--', 'N': '-.', @@ -2100,27 +2099,21 @@ def remorse_generate_morsede(): '?': '..--..', '=': '-...-', ';': '-.-.-.', ':': '---...', '/': '-..-.', '.': '.-.-.-', '-': '-....-', ',': '--..--', '+': '.-.-.', ')': '-.--.-', '(': '-.--.', "'": '.----.', 'SS': '...--..'} - ofile = open("./data/morse-de.dic", "a", encoding="iso-8859-15") - ofile.write("-----,0\n.----,1\n..---,2\n...--,3\n....-,4\n.....,5\n-....,6\n--...,7\n---..,8\n----.,9\n") - ofile.write(".-,A\n-...,B\n-.-.,C\n-..,D\n.,E\n..-.,F\n--.,G\n....,H\n..,I\n.---,J\n-.-,K\n.-..,L\n--,M\n") - ofile.write("-.,N\n---,O\n.--.,P\n--.-,Q\n.-.,R\n...,S\n-,T\n..-,U\n...-,V\n.--,W\n-..-,X\n-.--,Y\n--..,Z\n") - ofile.write("--.--,Ñ\n..-..,É\n.-..-,È\n.--.-,À\n..--,Ü\n---.,Ö\n.-.-,Ä\n..--.-,_\n.--.-.,@\n..--..,?\n-...-,=\n") - ofile.write("-.-.-.,;\n---...,:\n-..-.,/\n.-.-.-,.\n-....-,-\n.-.-.,+\n-.--.-,)\n-.--.,(\n.----.,'\n...--..,ß\n") - file = open("./data/german.dic", "r", encoding="iso-8859-15") - for zeile in file: - omsg = "" - zeile = zeile.rstrip() - try: - for char in zeile: - omsg = omsg + alphabet[char.upper()] - except TypeError: - continue - else: - ofile.write(omsg + "," + zeile + "\n") - file.close() + with open("./data/morse-de.dic", "w", encoding="iso-8859-1") as ofile: + for symbol, morse in alphabet.items(): + ofile.write(f"{morse},{symbol}\n") + with open("./data/german.dic", "r", encoding="iso-8859-1") as infile: + for line in infile: + word = line.strip() + try: + morse_word = ''.join(alphabet[char.upper()] for char in word) + ofile.write(f"{morse_word},{word}\n") + except KeyError: + # Überspringe Wörter mit nicht-unterstützten Zeichen + continue + infile.close() ofile.close() - def remorse_en(): hilfetext = """HILFE: [RE-Morse EN] Es gibt ja so Leute, die finden es lustig einen