From 525955c058c3ba9ffdc6f29271fcd29d402978ec Mon Sep 17 00:00:00 2001 From: KatKatKateryna Date: Mon, 7 Oct 2024 19:23:57 +0100 Subject: [PATCH] clean patch --- pygeoapi/flask_app.py | 23 ++----------------- pygeoapi/provider/speckle.py | 1 + .../provider/speckle_utils/coords_utils.py | 3 +-- .../provider/speckle_utils/server_utils.py | 1 + 4 files changed, 5 insertions(+), 23 deletions(-) diff --git a/pygeoapi/flask_app.py b/pygeoapi/flask_app.py index bd8dec7..8bb3ae7 100644 --- a/pygeoapi/flask_app.py +++ b/pygeoapi/flask_app.py @@ -173,24 +173,7 @@ def execute_from_flask(api_function, request: Request, *args, def handle_client(url_route: str): - try: - from geopy.geocoders import Nominatim - except ModuleNotFoundError: - from subprocess import run - import sys - - completed_process = run( - [ - sys.executable, - "-m", - "pip", - "install", - "geopy==2.4.1", - ], - capture_output=True, - ) - #if completed_process.returncode != 0: - from geopy.geocoders import Nominatim + from geopy.geocoders import Nominatim # if called fromm the browser, Exceptions from this function will result in infinite load agent = request.headers.get('User-Agent') @@ -216,6 +199,7 @@ def handle_client(url_route: str): country_code = "" try: geolocator = Nominatim(user_agent="specklePygeoapi") + lat = float(url_lower.split("&lat=")[1].split("&")[0]) lon = float(url_lower.split("&lon=")[1].split("&")[0]) @@ -230,8 +214,6 @@ def handle_client(url_route: str): if country_code == "ru": print(f"Validating project location: blocked LAT LON {lat}, {lon}") raise PermissionError("Review Speckle Terms and Conditions") - else: - print(f"Error validating project location: LAT LON {lat}, {lon}") # by IP: try: @@ -284,7 +266,6 @@ def landing_page(): # if requested from the browser, return this, otherwise ignore IF statement if request.method == 'GET' and browser_agent: # list items - print("browser") return Response(stream_with_context(generate())) # for non-browsers diff --git a/pygeoapi/provider/speckle.py b/pygeoapi/provider/speckle.py index e2fcad9..020e4ae 100644 --- a/pygeoapi/provider/speckle.py +++ b/pygeoapi/provider/speckle.py @@ -128,6 +128,7 @@ class SpeckleProvider(BaseProvider): self.commit_gis = False self.url_params = {"url_data_type":"", "url_preserve_attributes":"", "url_crs_authid":"", "url_lat":"","url_lon":"","url_north_degrees":"","url_limit":""} self.times = {} + self.country_code = "" self.requested_data_type: str = "polygons (default)" # points, lines, polygons, projectcomments self.preserve_attributes: str = "true (default)" diff --git a/pygeoapi/provider/speckle_utils/coords_utils.py b/pygeoapi/provider/speckle_utils/coords_utils.py index 8f00801..ae82349 100644 --- a/pygeoapi/provider/speckle_utils/coords_utils.py +++ b/pygeoapi/provider/speckle_utils/coords_utils.py @@ -126,9 +126,8 @@ def validate_coords(self, coords): country_code = address.get('country_code', '') except Exception as e: print(f"Error validating project location: {e}") + self.country_code = country_code if country_code == "ru": print(f"Validating project location: blocked LAT LON {coords[1]}, {coords[0]}") raise PermissionError("Review Speckle Terms and Conditions") - else: - print(f"Error validating project location: LAT LON {coords[1]}, {coords[0]}") diff --git a/pygeoapi/provider/speckle_utils/server_utils.py b/pygeoapi/provider/speckle_utils/server_utils.py index 1471e85..d06395f 100644 --- a/pygeoapi/provider/speckle_utils/server_utils.py +++ b/pygeoapi/provider/speckle_utils/server_utils.py @@ -225,6 +225,7 @@ def set_actions(self: "SpeckleProvider", client: "SpeckleClient", action: str = full_dict["model"] = f"{self.project_name}, {self.model_name}" full_dict["time_TOTAL"] = sum([x[1] for x in self.times.items()]) full_dict["model_url"] = self.speckle_url + full_dict["country_code"] = self.country_code track(action, client.account, full_dict) except Exception as ex: print(f"_Cannot set action '{action}': {ex}")