43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
import json
|
|
import mariadb
|
|
from .DB.DbManager import DbManager
|
|
|
|
|
|
|
|
class AddCity:
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.__con = DbManager().getConnection()
|
|
if self.__con:
|
|
self.__cur = self.__con.cursor()
|
|
|
|
def addPlz(self):
|
|
count = 1
|
|
with open("/home/dstoppek/Downloads/postleitzahl.json", "r") as plz:
|
|
postcodes = json.load(plz)
|
|
try:
|
|
for i in postcodes:
|
|
test =i["plz_name"].split(",")
|
|
for town in test:
|
|
|
|
if "u.a" in town:
|
|
town = town[:-4]
|
|
town = town.strip()
|
|
if town:
|
|
|
|
|
|
print(f"PROCESSING {i['name']} {town}")
|
|
self.__cur.callproc("addZipCodes", (i["name"], town, count,))
|
|
|
|
|
|
#time.sleep(1)
|
|
# self.__cur.execute(f"INSERT INTO postcode(postcode, addressid) VALUE ({i["name"]}, {count})")
|
|
# count += 1
|
|
|
|
except mariadb.OperationalError as e:
|
|
print(f"Database Error: {e}")
|
|
finally:
|
|
self.__con.commit()
|
|
print("FINISHED")
|
|
|