„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,7 +1,8 @@
import re import re
import json import json
import string
text_file = open(r"Name.txt", "r") text_file = open(r"Personen.txt", "r")
data = text_file.readlines() data = text_file.readlines()
arr = [None] * len(data) arr = [None] * len(data)
counter = 1 counter = 1
@ -10,12 +11,13 @@ 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]
telefon = telefon.replace("\n", "")
titel = re.search("^.*\.$",name_array[0]) titel = re.search("^.*\.$",name_array[0])
@ -40,15 +42,19 @@ for line in data:
nachname = name_array[1] nachname = name_array[1]
zweitname = None zweitname = None
adresse_array = re.split("\s", adresse) # adresse_array = re.split("\s", adresse)
plz = re.findall("\d{5}", adresse) plz = re.findall("\d{5}", adresse2)
hausnummer = re.findall(r"\b\d{1,4}\b", adresse) hausnummer = re.findall(r"\b\d{1,4}\b", adresse1)
chars = re.split("\d",adresse) strasse_chars = re.findall("\D",adresse1)
strasse = chars[0] strasse = ''.join(strasse_chars)
ort = adresse_array[len(adresse_array)-1] 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) 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 = { person = {
"Index" : counter, "Index" : counter,
@ -66,9 +72,9 @@ for line in data:
arr[counter - 1] = person arr[counter - 1] = person
counter = counter + 1 counter = counter + 1
print(counter)
with open(r"PersonenNeu.json", "w") as f:
with open(r"PersonNeu.json", "w") as f:
json.dump(arr,f, indent=1, ensure_ascii=False) json.dump(arr,f, indent=1, ensure_ascii=False)
f.close() f.close()