72 lines
2.0 KiB
Python
72 lines
2.0 KiB
Python
|
import re
|
||
|
import json
|
||
|
|
||
|
text_file = open(r"C:\Users\denni\Documents\Bundeswehr\HSMA\PR3\Steinberger\SL2\Name.txt", "r")
|
||
|
data = text_file.readlines()
|
||
|
arr = [None] * len(data)
|
||
|
counter = 1
|
||
|
|
||
|
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)
|
||
|
# strasse = re.findall(r"\b[A-Z]",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"C:\Users\denni\Documents\Bundeswehr\HSMA\PR3\Steinberger\SL2\PersonNeu.json", "w") as f:
|
||
|
json.dump(arr,f)
|