Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom data_dir override #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions geocode/geocode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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')

Expand Down Expand Up @@ -324,4 +327,3 @@ def _get_location_types(self, location_types):
continue
_location_types.append(_t)
return _location_types