From 4e867c86d8e46d60ebf91d96995aed95669e2957 Mon Sep 17 00:00:00 2001 From: KatKatKateryna Date: Wed, 4 Sep 2024 16:04:45 +0100 Subject: [PATCH] ensure speckleURL argument --- pygeoapi/api/itemtypes.py | 81 +++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 37 deletions(-) diff --git a/pygeoapi/api/itemtypes.py b/pygeoapi/api/itemtypes.py index cb4ede8..8a23e30 100644 --- a/pygeoapi/api/itemtypes.py +++ b/pygeoapi/api/itemtypes.py @@ -581,43 +581,50 @@ def get_collection_items( crsauthid = False for item in url_props: # if CRS authid is found, rest will be ignored - if "speckleurl=" in item: - content['speckle_url'] = item.split("speckleurl=")[1] - if content['speckle_url'][-1] == "/": - content['speckle_url'] = content['speckle_url'][:-1] - content['speckle_project_url'] = content['speckle_url'].split("/models")[0] - elif "datatype=" in item: - content['requested_data_type'] = item.split("datatype=")[1] - if content['requested_data_type'] not in ["points", "lines", "polygons", "projectcomments"]: - content['requested_data_type'] = "polygons (default)" - elif "preserveattributes=" in item: - content['preserve_attributes'] = item.split("preserveattributes=")[1] - if content['preserve_attributes'] not in ["true", "false"]: - content['preserve_attributes'] = "true (default)" - elif "crsauthid=" in item: - content['crs_authid'] = item.split("crsauthid=")[1] - crsauthid = True - elif "lat=" in item: - try: - content['lat'] = float(item.split("lat=")[1]) - except: - content['lat'] = f"Invalid input, must be numeric: {item.split('lat=')[1]}" - elif "lon=" in item: - try: - content['lon'] = float(item.split("lon=")[1]) - except: - content['lon'] = f"Invalid input, must be numeric: {item.split('lon=')[1]}" - elif "northdegrees=" in item: - try: - content['north_degrees'] = float(item.split("northdegrees=")[1]) - except: - content['north_degrees'] = f"Invalid input, must be numeric: {item.split('northdegrees=')[1]}" - elif "limit=" in item: - try: - content['limit'] = float(item.split("limit=")[1]) - except: - content['limit'] = f"Invalid input, must be integer: {item.split('limit=')[1]}" - + try: + + if "speckleurl=" in item: + try: + content['speckle_url'] = item.split("speckleurl=")[1] + if content['speckle_url'][-1] == "/": + content['speckle_url'] = content['speckle_url'][:-1] + content['speckle_project_url'] = content['speckle_url'].split("/models")[0] + except IndexError: + raise KeyError("Provide valid Speckle Model URL") + elif "datatype=" in item: + content['requested_data_type'] = item.split("datatype=")[1] + if content['requested_data_type'] not in ["points", "lines", "polygons", "projectcomments"]: + content['requested_data_type'] = "polygons (default)" + elif "preserveattributes=" in item: + content['preserve_attributes'] = item.split("preserveattributes=")[1] + if content['preserve_attributes'] not in ["true", "false"]: + content['preserve_attributes'] = "true (default)" + elif "crsauthid=" in item: + content['crs_authid'] = item.split("crsauthid=")[1] + crsauthid = True + elif "lat=" in item: + try: + content['lat'] = float(item.split("lat=")[1]) + except: + content['lat'] = f"Invalid input, must be numeric: {item.split('lat=')[1]}" + elif "lon=" in item: + try: + content['lon'] = float(item.split("lon=")[1]) + except: + content['lon'] = f"Invalid input, must be numeric: {item.split('lon=')[1]}" + elif "northdegrees=" in item: + try: + content['north_degrees'] = float(item.split("northdegrees=")[1]) + except: + content['north_degrees'] = f"Invalid input, must be numeric: {item.split('northdegrees=')[1]}" + elif "limit=" in item: + try: + content['limit'] = float(item.split("limit=")[1]) + except: + content['limit'] = f"Invalid input, must be integer: {item.split('limit=')[1]}" + except IndexError: + pass + if content['speckle_url'] == "-": content['missing_url'] = "true"