1+ """
2+ Import order here is a touch weird, but we need it so
3+ types exist before attempting to import functions that
4+ may call them
5+ """
6+
17import copy
28import requests
39from schemas import enrich_resp_schema
713 session ,
814)
915
10- OSM_DELAY = 1.0 # 1 second between requests as per OSM policy
11- WIKIDATA_DELAY = 0.5 # Be respectful to Wikidata
12- WIKIPEDIA_DELAY = 0.5 # Be respectful to Wikipedia
13-
14- # default to Washington, D.C.?
15- default_coords : dict = {
16- "latitude" : 38.89511000 ,
17- "longitude" : - 77.03637000 ,
18- }
19-
2016
2117class Enrichment (object ):
22- required_keys = [
18+ _required_keys = [
2319 "facility_name" ,
2420 ]
21+ # in seconds
22+ _wait_time : float = 1
2523
2624 def __init__ (self , ** kwargs ):
2725 self .resp_info = copy .deepcopy (enrich_resp_schema )
28- for k in self .required_keys :
26+ for k in self ._required_keys :
2927 if k not in kwargs .keys ():
3028 raise KeyError ("Missing required key %s in %s" , k , kwargs )
3129 self .search_args = copy .deepcopy (kwargs )
32- self .wait_time = int (kwargs .get ("wait_time" , 1 ))
3330
3431 def search (self ) -> dict :
3532 """Child objects should implement this"""
3633 return {}
3734
38- def _req (
39- self , url : str , params : dict = {}, timeout : int = 10 , stream : bool = False , headers : dict = default_headers
40- ) -> requests .Response :
35+ def _req (self , url : str , ** kwargs ) -> requests .Response :
4136 """requests response wrapper to ensure we honor waits"""
42-
37+ headers = kwargs . get ( "headers" , {})
4338 # ensure we get all headers configured correctly
4439 # but manually applied headers win the argument
4540 for k , v in default_headers .items ():
@@ -48,10 +43,15 @@ def _req(
4843 headers [k ] = v
4944
5045 response = session .get (
51- url , allow_redirects = True , timeout = timeout , params = params , stream = stream , headers = headers
46+ url ,
47+ allow_redirects = True ,
48+ timeout = kwargs .get ("timeout" , 10 ),
49+ params = kwargs .get ("params" , {}),
50+ stream = kwargs .get ("stream" , False ),
51+ headers = headers ,
5252 )
5353 response .raise_for_status ()
54- time .sleep (self .wait_time )
54+ time .sleep (self ._wait_time )
5555 return response
5656
5757 def _minimal_clean_facility_name (self , name : str ) -> str :
0 commit comments