From 39b1a8acc1f5cf04bed27fee4fb9e37253049289 Mon Sep 17 00:00:00 2001 From: Ian Turton Date: Wed, 31 May 2023 09:49:21 +0100 Subject: [PATCH 1/2] add an adjustable delay to avoid rate limit --- src/osdatahub/FeaturesAPI/features_api.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/osdatahub/FeaturesAPI/features_api.py b/src/osdatahub/FeaturesAPI/features_api.py index e65a50b..efa5e83 100644 --- a/src/osdatahub/FeaturesAPI/features_api.py +++ b/src/osdatahub/FeaturesAPI/features_api.py @@ -1,4 +1,5 @@ import json +import time import warnings import requests @@ -15,6 +16,7 @@ from osdatahub.spatial_filter_types import SpatialFilterTypes from osdatahub.utils import features_to_geojson, is_new_api + class FeaturesAPI: """Main class for querying the OS Features API (https://osdatahub.os.uk/docs/wfs/overview) @@ -82,7 +84,7 @@ def product(self, product_name: str): def xml_filter(self): return self.__construct_filter() - def query(self, limit: int = 100) -> FeatureCollection: + def query(self, limit: int = 100, delay: int = 60) -> FeatureCollection: """Run a query of the OS Features API Args: @@ -111,6 +113,7 @@ def query(self, limit: int = 100) -> FeatureCollection: self.product = self.__product_name data.extend(resp_json["features"]) n_required = min(100, limit - len(data)) + time.sleep(delay) except json.decoder.JSONDecodeError: raise_http_error(response) From 821bc2497b14d55d3f3924270b7e6ddf8dcb73c3 Mon Sep 17 00:00:00 2001 From: "Ian Turton (at Work)" Date: Wed, 31 May 2023 11:31:22 +0100 Subject: [PATCH 2/2] remove uneeded imports to shut flake 8 up --- src/osdatahub/FeaturesAPI/features_api.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/osdatahub/FeaturesAPI/features_api.py b/src/osdatahub/FeaturesAPI/features_api.py index efa5e83..ee26be2 100644 --- a/src/osdatahub/FeaturesAPI/features_api.py +++ b/src/osdatahub/FeaturesAPI/features_api.py @@ -2,7 +2,6 @@ import time import warnings -import requests from geojson import FeatureCollection from typeguard import check_argument_types @@ -155,8 +154,6 @@ def add_filters(self, *xml_filters: Filter) -> None: if __name__ == "__main__": from os import environ - from osdatahub import Extent, FeaturesAPI - key = environ.get("OS_API_KEY") bbox = (-1.5339625, 53.787380, -1.5266132, 53.794103)