From 905a079e306f74137336d7107fc819a6e30aed4f Mon Sep 17 00:00:00 2001 From: Mladen Gibanica <11275336+mgcth@users.noreply.github.com> Date: Wed, 22 May 2024 19:22:55 +0200 Subject: [PATCH] Add rate limiter to nominatim --- src/smhi/smhi.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/smhi/smhi.py b/src/smhi/smhi.py index 6c1645c..6b812d1 100644 --- a/src/smhi/smhi.py +++ b/src/smhi/smhi.py @@ -6,6 +6,7 @@ import pandas as pd from geopy import distance +from geopy.extra.rate_limiter import RateLimiter from geopy.geocoders import Nominatim from smhi.metobs import Data, Parameters, Periods, Stations from smhi.models.metobs_model import MetobsLinks @@ -143,7 +144,8 @@ def _find_stations_by_city( nearby stations """ geolocator = Nominatim(user_agent="ifk-smhi") - loc = geolocator.geocode(city) + geocode = RateLimiter(geolocator.geocode, min_delay_seconds=1) + loc = geocode(city) return self._find_stations_from_gps( station_response, latitude=loc.latitude, longitude=loc.longitude, dist=dist