Added importCountry
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
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")
|
||||
|
||||
@@ -8,10 +8,12 @@ class AddressDAO:
|
||||
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)
|
||||
@@ -31,6 +33,36 @@ class AddressDAO:
|
||||
self.__con.commit()
|
||||
print("FINISHED")#
|
||||
|
||||
def __importCountry(self):
|
||||
with open("/home/dstoppek/Downloads/staaten.json", "r") as country:
|
||||
countries = json.load(country)
|
||||
old = ""
|
||||
try:
|
||||
for i in countries["daten"]:
|
||||
if i[4] == "–":
|
||||
continue
|
||||
elif i[8] == "YU":
|
||||
continue
|
||||
elif i[4] == old:
|
||||
continue
|
||||
elif i[4] == "Serbien und Montenegro":
|
||||
continue
|
||||
elif i[4] == "Bosnien und Herzegowina":
|
||||
continue
|
||||
|
||||
print(i[4], i[3], i[2], i[8], i[7])
|
||||
|
||||
self.__cur.execute("INSERT INTO country (country, countryshort, nationality, iso2, iso3) VALUES (%s, %s, %s, %s, %s)", (i[4], i[3], i[2], i[8], i[7]))
|
||||
old = i[4]
|
||||
except mariadb.OperationalError as e:
|
||||
print(f"Database Error: {e}")
|
||||
finally:
|
||||
self.__con.commit()
|
||||
print("FINISHED")#
|
||||
|
||||
|
||||
|
||||
|
||||
def getAddressData(self, all = True, zipcode = None):
|
||||
try:
|
||||
if self.__cur:
|
||||
|
||||
Reference in New Issue
Block a user