2023-01-11 09:20:51 +01:00
|
|
|
import re
|
|
|
|
import json
|
|
|
|
import string
|
|
|
|
|
|
|
|
text_file = open(r"Personen.txt", "r")
|
|
|
|
data = text_file.readlines()
|
2023-01-12 12:50:06 +01:00
|
|
|
|
2023-01-11 09:20:51 +01:00
|
|
|
arr = [None] * len(data)
|
|
|
|
counter = 1
|
|
|
|
text_file.close()
|
|
|
|
|
|
|
|
for line in data:
|
2023-01-12 12:50:06 +01:00
|
|
|
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", "")
|
2023-01-11 09:20:51 +01:00
|
|
|
|
2023-01-12 12:50:06 +01:00
|
|
|
titel = re.search("^.*\.$",name_array[0])
|
2023-01-11 09:20:51 +01:00
|
|
|
|
|
|
|
|
2023-01-12 12:50:06 +01:00
|
|
|
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
|
2023-01-11 09:20:51 +01:00
|
|
|
else:
|
2023-01-12 12:50:06 +01:00
|
|
|
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
|
2023-01-11 09:20:51 +01:00
|
|
|
|
2023-01-12 12:50:06 +01:00
|
|
|
# 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("\"", "")
|
2023-01-11 09:20:51 +01:00
|
|
|
|
|
|
|
|
2023-01-12 12:50:06 +01:00
|
|
|
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)
|
2023-01-11 09:20:51 +01:00
|
|
|
|
2023-01-12 12:50:06 +01:00
|
|
|
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
|
|
|
|
except:
|
|
|
|
continue
|
2023-01-11 09:20:51 +01:00
|
|
|
|
|
|
|
with open(r"PersonenNeu.json", "w") as f:
|
|
|
|
json.dump(arr,f, indent=1, ensure_ascii=False)
|
|
|
|
|
2023-01-10 13:29:30 +01:00
|
|
|
f.close()
|