„SL2/s2_a3.py“ ändern

angepasst an neue Personen Datei
Main
Dennis Krämer 2023-01-11 09:20:51 +01:00
parent b5eb02db6b
commit 588529032e
1 changed files with 79 additions and 73 deletions

View File

@ -1,74 +1,80 @@
import re import re
import json import json
import string
text_file = open(r"Name.txt", "r")
data = text_file.readlines() text_file = open(r"Personen.txt", "r")
arr = [None] * len(data) data = text_file.readlines()
counter = 1 arr = [None] * len(data)
text_file.close() counter = 1
text_file.close()
for line in data:
for line in data:
data_array = re.split(", ", line)
data_array = re.split(",", line)
name = data_array[0] name = data_array[0]
name_array = re.split("\s",name) name_array = re.split("\s",name)
adresse = data_array[1] adresse1 = data_array[1]
geburtsdatum = data_array[2] adresse2 = data_array[2]
telefon = data_array[3] geburtsdatum = data_array[3]
telefon = data_array[4]
titel = re.search("^.*\.$",name_array[0]) telefon = telefon.replace("\n", "")
titel = re.search("^.*\.$",name_array[0])
if titel != None:
titel = titel.string
if len(name_array) == 4: if titel != None:
vorname = name_array[1] titel = titel.string
zweitname = name_array[2] if len(name_array) == 4:
nachname = name_array[3] vorname = name_array[1]
else: zweitname = name_array[2]
vorname = name_array[1] nachname = name_array[3]
nachname = name_array[2] else:
zweitname = None vorname = name_array[1]
else: nachname = name_array[2]
if len(name_array) == 3: zweitname = None
vorname = name_array[0] else:
zweitname = name_array[1] if len(name_array) == 3:
nachname = name_array[2] vorname = name_array[0]
else: zweitname = name_array[1]
vorname = name_array[0] nachname = name_array[2]
nachname = name_array[1] else:
zweitname = None vorname = name_array[0]
nachname = name_array[1]
adresse_array = re.split("\s", adresse) zweitname = None
plz = re.findall("\d{5}", adresse)
hausnummer = re.findall(r"\b\d{1,4}\b", adresse) # adresse_array = re.split("\s", adresse)
chars = re.split("\d",adresse) plz = re.findall("\d{5}", adresse2)
strasse = chars[0] hausnummer = re.findall(r"\b\d{1,4}\b", adresse1)
ort = adresse_array[len(adresse_array)-1] strasse_chars = re.findall("\D",adresse1)
strasse = ''.join(strasse_chars)
geburtsdatum = re.findall("[0-9][0-9]\.[0-9][0-9]\.[0-9][0-9][0-9][0-9]", line) strasse = strasse.replace("\"", "")
telefon = re.findall("\d{6,20}", line) ort_chars = re.findall("\D",adresse2)
ort = ''.join(ort_chars)
person = { ort = ort.replace("\"", "")
"Index" : counter,
"Titel" : titel,
"Vorname" : vorname, geburtsdatum = re.findall("[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]", line)
"Zweitname" : zweitname, # telefon = re.findall("\d{6,20}", line)
"Nachname" : nachname,
"Geburtsdatum" : geburtsdatum, person = {
"Strasse" : strasse, "Index" : counter,
"Hausnummer" : hausnummer, "Titel" : titel,
"PLZ" : plz, "Vorname" : vorname,
"Wohnort" : ort, "Zweitname" : zweitname,
"Rufnummer" : telefon "Nachname" : nachname,
} "Geburtsdatum" : geburtsdatum,
"Strasse" : strasse,
arr[counter - 1] = person "Hausnummer" : hausnummer,
counter = counter + 1 "PLZ" : plz,
"Wohnort" : ort,
"Rufnummer" : telefon
with open(r"PersonNeu.json", "w") as f: }
json.dump(arr,f, indent=1, ensure_ascii=False)
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() f.close()