„SL2/s2_a3.py“ ändern
parent
588529032e
commit
fc34a84e3b
112
SL2/s2_a3.py
112
SL2/s2_a3.py
|
@ -4,75 +4,77 @@ import string
|
||||||
|
|
||||||
text_file = open(r"Personen.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
|
||||||
text_file.close()
|
text_file.close()
|
||||||
|
|
||||||
for line in data:
|
for line in data:
|
||||||
|
try:
|
||||||
|
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", "")
|
||||||
|
|
||||||
data_array = re.split(",", line)
|
titel = re.search("^.*\.$",name_array[0])
|
||||||
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:
|
if titel != None:
|
||||||
titel = titel.string
|
titel = titel.string
|
||||||
if len(name_array) == 4:
|
if len(name_array) == 4:
|
||||||
vorname = name_array[1]
|
vorname = name_array[1]
|
||||||
zweitname = name_array[2]
|
zweitname = name_array[2]
|
||||||
nachname = name_array[3]
|
nachname = name_array[3]
|
||||||
|
else:
|
||||||
|
vorname = name_array[1]
|
||||||
|
nachname = name_array[2]
|
||||||
|
zweitname = None
|
||||||
else:
|
else:
|
||||||
vorname = name_array[1]
|
if len(name_array) == 3:
|
||||||
nachname = name_array[2]
|
vorname = name_array[0]
|
||||||
zweitname = None
|
zweitname = name_array[1]
|
||||||
else:
|
nachname = name_array[2]
|
||||||
if len(name_array) == 3:
|
else:
|
||||||
vorname = name_array[0]
|
vorname = name_array[0]
|
||||||
zweitname = name_array[1]
|
nachname = name_array[1]
|
||||||
nachname = name_array[2]
|
zweitname = None
|
||||||
else:
|
|
||||||
vorname = name_array[0]
|
|
||||||
nachname = name_array[1]
|
|
||||||
zweitname = None
|
|
||||||
|
|
||||||
# adresse_array = re.split("\s", adresse)
|
# adresse_array = re.split("\s", adresse)
|
||||||
plz = re.findall("\d{5}", adresse2)
|
plz = re.findall("\d{5}", adresse2)
|
||||||
hausnummer = re.findall(r"\b\d{1,4}\b", adresse1)
|
hausnummer = re.findall(r"\b\d{1,4}\b", adresse1)
|
||||||
strasse_chars = re.findall("\D",adresse1)
|
strasse_chars = re.findall("\D",adresse1)
|
||||||
strasse = ''.join(strasse_chars)
|
strasse = ''.join(strasse_chars)
|
||||||
strasse = strasse.replace("\"", "")
|
strasse = strasse.replace("\"", "")
|
||||||
ort_chars = re.findall("\D",adresse2)
|
ort_chars = re.findall("\D",adresse2)
|
||||||
ort = ''.join(ort_chars)
|
ort = ''.join(ort_chars)
|
||||||
ort = ort.replace("\"", "")
|
ort = ort.replace("\"", "")
|
||||||
|
|
||||||
|
|
||||||
geburtsdatum = re.findall("[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]", 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)
|
# telefon = re.findall("\d{6,20}", line)
|
||||||
|
|
||||||
person = {
|
person = {
|
||||||
"Index" : counter,
|
"Index" : counter,
|
||||||
"Titel" : titel,
|
"Titel" : titel,
|
||||||
"Vorname" : vorname,
|
"Vorname" : vorname,
|
||||||
"Zweitname" : zweitname,
|
"Zweitname" : zweitname,
|
||||||
"Nachname" : nachname,
|
"Nachname" : nachname,
|
||||||
"Geburtsdatum" : geburtsdatum,
|
"Geburtsdatum" : geburtsdatum,
|
||||||
"Strasse" : strasse,
|
"Strasse" : strasse,
|
||||||
"Hausnummer" : hausnummer,
|
"Hausnummer" : hausnummer,
|
||||||
"PLZ" : plz,
|
"PLZ" : plz,
|
||||||
"Wohnort" : ort,
|
"Wohnort" : ort,
|
||||||
"Rufnummer" : telefon
|
"Rufnummer" : telefon
|
||||||
}
|
}
|
||||||
|
|
||||||
arr[counter - 1] = person
|
arr[counter - 1] = person
|
||||||
counter = counter + 1
|
counter = counter + 1
|
||||||
print(counter)
|
except:
|
||||||
|
continue
|
||||||
|
|
||||||
with open(r"PersonenNeu.json", "w") as f:
|
with open(r"PersonenNeu.json", "w") as f:
|
||||||
json.dump(arr,f, indent=1, ensure_ascii=False)
|
json.dump(arr,f, indent=1, ensure_ascii=False)
|
||||||
|
|
Loading…
Reference in New Issue