Skip to content

Commit

Permalink
Add rate limiter to nominatim
Browse files Browse the repository at this point in the history
  • Loading branch information
mgcth committed May 22, 2024
1 parent 3b7dc36 commit 905a079
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/smhi/smhi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 905a079

Please sign in to comment.