diff --git a/SL2/s2_a3.py b/SL2/s2_a3.py index 5e770a3..ebbf1da 100644 --- a/SL2/s2_a3.py +++ b/SL2/s2_a3.py @@ -1,74 +1,80 @@ -import re -import json - -text_file = open(r"Name.txt", "r") -data = text_file.readlines() -arr = [None] * len(data) -counter = 1 -text_file.close() - -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) - 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"PersonNeu.json", "w") as f: - json.dump(arr,f, indent=1, ensure_ascii=False) - +import re +import json +import string + +text_file = open(r"Personen.txt", "r") +data = text_file.readlines() +arr = [None] * len(data) +counter = 1 +text_file.close() + +for line in data: + + data_array = re.split(",", line) + name = data_array[0] + name_array = re.split("\s",name) + adresse1 = data_array[1] + adresse2 = data_array[2] + geburtsdatum = data_array[3] + telefon = data_array[4] + telefon = telefon.replace("\n", "") + + 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}", adresse2) + hausnummer = re.findall(r"\b\d{1,4}\b", adresse1) + strasse_chars = re.findall("\D",adresse1) + strasse = ''.join(strasse_chars) + strasse = strasse.replace("\"", "") + ort_chars = re.findall("\D",adresse2) + ort = ''.join(ort_chars) + ort = ort.replace("\"", "") + + + 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 + print(counter) + +with open(r"PersonenNeu.json", "w") as f: + json.dump(arr,f, indent=1, ensure_ascii=False) + f.close() \ No newline at end of file