diff --git a/bin/continents.py b/bin/continents.py index bcdb29c..7e75248 100755 --- a/bin/continents.py +++ b/bin/continents.py @@ -8,6 +8,8 @@ import httpx +ACCOUNT_ERR_CODE = 10 + # see http://download.geonames.org/export/dump/readme.txt continent_ids = [6255146, 6255147, 6255148, 6255149, 6255151, 6255150, 6255152] url = 'http://api.geonames.org/getJSON' @@ -20,7 +22,7 @@ def account_ok(j): - if j.get('status', {}).get('value') == 10: + if j.get('status', {}).get('value') == ACCOUNT_ERR_CODE: print(j['status']['message']) sys.exit(1) diff --git a/bin/us_counties.py b/bin/us_counties.py index 2fde38a..5fefd19 100755 --- a/bin/us_counties.py +++ b/bin/us_counties.py @@ -3,15 +3,10 @@ import json from pathlib import Path -counties = [] p_data = Path('data') reader = csv.reader(p_data.joinpath('us_counties.txt').open()) -for line in reader: - counties.append({ - 'fips': line[1] + line[2], - 'name': line[3], - 'state': line[0] - }) + +counties = [{'fips': line[1] + line[2], 'name': line[3], 'state': line[0]} for line in reader] p_data.joinpath('us_counties.json').write_text(json.dumps(counties)) diff --git a/geonamescache/__init__.py b/geonamescache/__init__.py index 38bfd48..82e896e 100644 --- a/geonamescache/__init__.py +++ b/geonamescache/__init__.py @@ -93,8 +93,9 @@ def search_cities( self, query: str, attribute: CitySearchAttribute = 'alternatenames', + *, case_sensitive: bool = False, - contains_search: bool = True, + contains_search: bool = True ) -> List[City]: """Search all city records and return list of records, that match query for given attribute.""" results = [] diff --git a/geonamescache/mappers.py b/geonamescache/mappers.py index 52c21e9..141ea48 100644 --- a/geonamescache/mappers.py +++ b/geonamescache/mappers.py @@ -45,12 +45,12 @@ def country( gc = GeonamesCache() dataset = gc.get_dataset_by_key(gc.get_countries(), from_key) - def mapper(input: str) -> Any: - # For country name inputs take the names mapping into account. + def mapper(value: str) -> Any: + # For country names take the mappings into account. if from_key == "name": - input = mappings.country_names.get(input, input) - # If there is a record return the demanded attribute. - item = dataset.get(input) + value = mappings.country_names.get(value, value) + # If there is a record return the corresponding attribute value. + item = dataset.get(value) if item: return item[to_key] return None