diff --git a/geocoder_script.py b/areg_linker_script.py similarity index 91% rename from geocoder_script.py rename to areg_linker_script.py index c473b7d21d20bc36d6471f778e9b13b4e23d101e..57b4c2b83b0e50aff6876e90942c484dce79f628 100644 --- a/geocoder_script.py +++ b/areg_linker_script.py @@ -1,75 +1,75 @@ -# script zum geocoden der schulen und zuweisen der URI aus dem AREG -from script_helper import DBTools, APITools -from configparser import ConfigParser - - -if __name__ == '__main__': - print("geocoding dataset now") - # datenbank mit den schuldaten - conn_config = ConfigParser() - conn_config.read("db_conn.cfg") - - conn_str = f""" - host={conn_config['connection']['host']} - port={conn_config['connection']['port']} - dbname={conn_config['connection']['dbname']} - user={conn_config['connection']['user']} - password={conn_config['connection']['pwd']}""" - table = conn_config['connection']['table'] - - url = conn_config['connection']['url'] - # logfile = r"geocoder.log" - - my_db = DBTools(conn_str) - my_api = APITools(url) - - schulen = my_db.select_adress(table) - adresse = {} - maxfeatures = len(schulen) - numfeatures = 0 - errorfeatures = 0 - missinfeatures = 0 - log = [] - - for item in schulen: - adresse["hnr"] = item[1] - adresse["stn"] = item[2] - adresse["plz"] = item[3] - adresse["ort"] = item[4] - - areg_response = my_api.geocode(adresse) - - if areg_response.get("uri") is not None: - areg_uri = areg_response["uri"] - my_db.update_uri(str(item[0]), areg_uri, table) - numfeatures += 1 - else: - areg_response_key = list(areg_response.keys()) - - if areg_response_key[0] == "MISSING": - missinfeatures += 1 - if areg_response_key[0] == "ERROR": - errorfeatures += 1 - - progress_msg = (f"{areg_response_key[0]} : " + - f"{areg_response[areg_response_key[0]]} | " + - f"betroffene schule: [{item[0]}]\t{adresse['hnr']};" + # noqa - f" {adresse['stn']}; {adresse['plz']}; " + - f"{adresse['ort']}") - - print(progress_msg) - - my_db.closecursor() - - # sorgt auf dem cloudserver fuer fehler wegen permission - # with open(logfile, "w", encoding='utf-8') as out: - # for item in log: - # out.write(item) - - percentage = round((numfeatures * 100) / maxfeatures, 2) - statistics = (f"statistics:\n {numfeatures} from {maxfeatures} geocoded" + - f" >> {percentage}%\n {missinfeatures} features with " + - f"missing attributes\n {errorfeatures} features with " + - f"errors\n") - print(statistics) - print("geocoding dataset finished, closing programm") +# script zum verlinken der schulen und zuweisen der URI aus dem AREG +from script_helper import DBTools, APITools +from configparser import ConfigParser + + +if __name__ == '__main__': + print("geocoding dataset now") + # datenbank mit den schuldaten + conn_config = ConfigParser() + conn_config.read("db_conn.cfg") + + conn_str = f""" + host={conn_config['connection']['host']} + port={conn_config['connection']['port']} + dbname={conn_config['connection']['dbname']} + user={conn_config['connection']['user']} + password={conn_config['connection']['pwd']}""" + table = conn_config['connection']['table'] + + url = conn_config['connection']['url'] + # logfile = r"geocoder.log" + + my_db = DBTools(conn_str) + my_api = APITools(url) + + schulen = my_db.select_adress(table) + adresse = {} + maxfeatures = len(schulen) + numfeatures = 0 + errorfeatures = 0 + missinfeatures = 0 + log = [] + + for item in schulen: + adresse["hnr"] = item[1] + adresse["stn"] = item[2] + adresse["plz"] = item[3] + adresse["ort"] = item[4] + + areg_response = my_api.geocode(adresse) + + if areg_response.get("uri") is not None: + areg_uri = areg_response["uri"] + my_db.update_uri(str(item[0]), areg_uri, table) + numfeatures += 1 + else: + areg_response_key = list(areg_response.keys()) + + if areg_response_key[0] == "MISSING": + missinfeatures += 1 + if areg_response_key[0] == "ERROR": + errorfeatures += 1 + + progress_msg = (f"{areg_response_key[0]} : " + + f"{areg_response[areg_response_key[0]]} | " + + f"betroffene schule: [{item[0]}]\t{adresse['hnr']};" + # noqa + f" {adresse['stn']}; {adresse['plz']}; " + + f"{adresse['ort']}") + + print(progress_msg) + + my_db.closecursor() + + # sorgt auf dem cloudserver fuer fehler wegen permission + # with open(logfile, "w", encoding='utf-8') as out: + # for item in log: + # out.write(item) + + percentage = round((numfeatures * 100) / maxfeatures, 2) + statistics = (f"statistics:\n {numfeatures} from {maxfeatures} linked" + + f" >> {percentage}%\n {missinfeatures} features with " + + f"missing attributes\n {errorfeatures} features with " + + f"errors\n") + print(statistics) + print("linking dataset finished, closing programm")