Better logging + cleanup.
authorScott Gasch <[email protected]>
Sun, 1 May 2022 00:42:14 +0000 (17:42 -0700)
committerScott Gasch <[email protected]>
Sun, 1 May 2022 00:42:14 +0000 (17:42 -0700)
geocode.py

index 176487ae566458093ecf0fd95a3d21ab98221418..15ffff07acfb888cb1e3f03f34277f78d44facc6 100644 (file)
@@ -7,6 +7,7 @@ https://www2.census.gov/geo/pdfs/maps-data/data/Census_Geocoder_User_Guide.pdf
 https://geocoding.geo.census.gov/geocoder/Geocoding_Services_API.pdf
 """
 
+import json
 import logging
 from typing import Any, Dict, List, Optional
 
@@ -43,9 +44,10 @@ def geocode_address(address: str) -> Optional[Dict[str, Any]]:
         return None
 
     if r.status_code != 200:
+        logger.debug(r.text)
         logger.error('Unexpected response code %d, wanted 200.  Fail.', r.status_code)
         return None
-    # print(json.dumps(r.json(), indent=4, sort_keys=True))
+    logger.debug('Response: %s', json.dumps(r.json(), indent=4, sort_keys=True))
     return r.json()
 
 
@@ -86,10 +88,12 @@ def batch_geocode_addresses(addresses: List[str]):
         except Exception as e:
             logger.exception(e)
             return None
+
         if r.status_code != 200:
-            print(r.text)
+            logger.debug(r.text)
             logger.error('Unexpected response code %d, wanted 200.  Fail.', r.status_code)
             return None
+        logger.debug('Response: %s', r.text)
         for line in r.text.split('\n'):
             line = line.strip()
             if len(line) > 0: