From: Scott Gasch Date: Sun, 1 May 2022 00:42:14 +0000 (-0700) Subject: Better logging + cleanup. X-Git-Url: https://wannabe.guru.org/gitweb/?a=commitdiff_plain;h=4b617c7e0e2ea9a83a2c7d98a18e2433c7c92a1a;p=python_utils.git Better logging + cleanup. --- diff --git a/geocode.py b/geocode.py index 176487a..15ffff0 100644 --- a/geocode.py +++ b/geocode.py @@ -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: