Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #90: add an adjustable delay to avoid rate limit #91

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/osdatahub/FeaturesAPI/features_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import time
import warnings

import requests
from geojson import FeatureCollection
from typeguard import check_argument_types

Expand All @@ -15,6 +15,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)

Expand Down Expand Up @@ -82,7 +83,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:
Expand Down Expand Up @@ -111,6 +112,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)

Expand Down Expand Up @@ -152,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)
Expand Down