41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
from .DbManager import DbManager
|
|
import mariadb
|
|
import json
|
|
|
|
|
|
class AddressDAO:
|
|
__cur = None
|
|
def __init__(self):
|
|
#print(f"*** File: {__file__}, init()")
|
|
self.__con = DbManager().getConnection()
|
|
if self.__con:
|
|
self.__cur = self.__con.cursor()
|
|
|
|
|
|
def __importPlz(self):
|
|
with open("import json filepath here", "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,))
|
|
except mariadb.OperationalError as e:
|
|
print(f"Database Error: {e}")
|
|
finally:
|
|
self.__con.commit()
|
|
print("FINISHED")#
|
|
|
|
def getAddressData(self, all = True, zipcode = None):
|
|
if self.__cur:
|
|
self.__cur.callproc("getAddress", (all, zipcode,))
|
|
self.__data = self.__cur.fetchall()
|
|
return self.__data
|
|
else:
|
|
return None
|