From b475ea40281339739bb28e0f1791a8ab98f55861 Mon Sep 17 00:00:00 2001 From: Nicos Date: Mon, 12 Feb 2024 12:20:06 +0000 Subject: [PATCH] Add custom data_dir override --- geocode/geocode.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/geocode/geocode.py b/geocode/geocode.py index 718dd4d..fa809eb 100644 --- a/geocode/geocode.py +++ b/geocode/geocode.py @@ -20,11 +20,12 @@ log = logging.getLogger(__name__) class Geocode(): - def __init__(self, min_population_cutoff=30000, large_city_population_cutoff=200000, location_types=None): + def __init__(self, min_population_cutoff=30000, large_city_population_cutoff=200000, location_types=None, data_dir_override=None): self.kp = None self.geo_data = None self.min_population_cutoff = min_population_cutoff self.large_city_population_cutoff = large_city_population_cutoff + self.data_dir_override = data_dir_override self.geo_data_field_names = ['name', 'official_name', 'country_code', 'longitude', 'latitude', 'geoname_id', 'location_type', 'population'] self.default_location_types = ['city', 'place', 'country', 'admin1', 'admin2', 'admin3', 'admin4', 'admin5', 'admin6', 'admin_other', 'continent', 'region'] self.location_types = self._get_location_types(location_types) @@ -99,6 +100,8 @@ def keyword_processor_pickle_path(self): @property def data_dir(self): + if self.data_dir_override: + return self.data_dir_override current_dir = os.path.dirname(os.path.abspath(__file__)) return os.path.join(current_dir, 'data') @@ -324,4 +327,3 @@ def _get_location_types(self, location_types): continue _location_types.append(_t) return _location_types -