From 0e3a09ba8de588cbc0b1295cee47dca9a6473050 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20Kr=C3=A4mer?= <2122684@stud.hs-mannheim.de> Date: Mon, 9 Jan 2023 14:16:43 +0100 Subject: [PATCH] =?UTF-8?q?Dateien=20hochladen=20nach=20=E2=80=9ESL2?= =?UTF-8?q?=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SL2/s2_a1.py | 13 ++++++++++ SL2/s2_a2.py | 4 +++ SL2/s2_a3.py | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 SL2/s2_a1.py create mode 100644 SL2/s2_a2.py create mode 100644 SL2/s2_a3.py diff --git a/SL2/s2_a1.py b/SL2/s2_a1.py new file mode 100644 index 0000000..0a7d061 --- /dev/null +++ b/SL2/s2_a1.py @@ -0,0 +1,13 @@ +class Tier: + def __init__(self,beine) -> None: + self.beine = beine + +class Hund(Tier): + def __init__(self, name): + super().__init__(4) + self.name = name + +class Rottweiler(Tier, Hund): + def __init__(self): + super().__init__(4, "Harald") + diff --git a/SL2/s2_a2.py b/SL2/s2_a2.py new file mode 100644 index 0000000..f1de2f9 --- /dev/null +++ b/SL2/s2_a2.py @@ -0,0 +1,4 @@ +import re +txt = "If the the problem is textual, use the the re module" +txt = re.sub("the the", "the", txt) +print(txt) \ No newline at end of file diff --git a/SL2/s2_a3.py b/SL2/s2_a3.py new file mode 100644 index 0000000..2532b68 --- /dev/null +++ b/SL2/s2_a3.py @@ -0,0 +1,72 @@ +import re +import json + +text_file = open(r"C:\Users\denni\Documents\Bundeswehr\HSMA\PR3\Steinberger\SL2\Name.txt", "r") +data = text_file.readlines() +arr = [None] * len(data) +counter = 1 + +for line in data: + + data_array = re.split(", ", line) + + name = data_array[0] + name_array = re.split("\s",name) + adresse = data_array[1] + geburtsdatum = data_array[2] + telefon = data_array[3] + + titel = re.search("^.*\.$",name_array[0]) + + + if titel != None: + titel = titel.string + if len(name_array) == 4: + vorname = name_array[1] + zweitname = name_array[2] + nachname = name_array[3] + else: + vorname = name_array[1] + nachname = name_array[2] + zweitname = None + else: + if len(name_array) == 3: + vorname = name_array[0] + zweitname = name_array[1] + nachname = name_array[2] + else: + vorname = name_array[0] + nachname = name_array[1] + zweitname = None + + adresse_array = re.split("\s", adresse) + plz = re.findall("\d{5}", adresse) + hausnummer = re.findall(r"\b\d{1,4}\b", adresse) + # strasse = re.findall(r"\b[A-Z]",adresse) + chars = re.split("\d",adresse) + strasse = chars[0] + ort = adresse_array[len(adresse_array)-1] + + geburtsdatum = re.findall("[0-9][0-9]\.[0-9][0-9]\.[0-9][0-9][0-9][0-9]", line) + telefon = re.findall("\d{6,20}", line) + + person = { + "Index" : counter, + "Titel" : titel, + "Vorname" : vorname, + "Zweitname" : zweitname, + "Nachname" : nachname, + "Geburtsdatum" : geburtsdatum, + "Strasse" : strasse, + "Hausnummer" : hausnummer, + "PLZ" : plz, + "Wohnort" : ort, + "Rufnummer" : telefon + } + + arr[counter - 1] = person + counter = counter + 1 + + +with open(r"C:\Users\denni\Documents\Bundeswehr\HSMA\PR3\Steinberger\SL2\PersonNeu.json", "w") as f: + json.dump(arr,f) \ No newline at end of file