Merge pull request #476 from CartoDB/Avoid_reaching_provider_for_empty_geocodings
Avoid reaching provider for empty geocodings
This commit is contained in:
commit
2f8edbe5ce
@ -64,18 +64,31 @@ class MapboxGeocoder(Traceable):
|
|||||||
latitude = location[1]
|
latitude = location[1]
|
||||||
return [longitude, latitude]
|
return [longitude, latitude]
|
||||||
|
|
||||||
|
def _validate_input(self, searchtext, city=None, state_province=None,
|
||||||
|
country=None):
|
||||||
|
if searchtext and searchtext.strip():
|
||||||
|
return True
|
||||||
|
elif city:
|
||||||
|
return True
|
||||||
|
elif state_province:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
@qps_retry(qps=10)
|
@qps_retry(qps=10)
|
||||||
def geocode(self, searchtext, city=None, state_province=None,
|
def geocode(self, searchtext, city=None, state_province=None,
|
||||||
country=None):
|
country=None):
|
||||||
if searchtext and searchtext.strip():
|
if not self._validate_input(searchtext, city, state_province, country):
|
||||||
address = [normalize(searchtext)]
|
|
||||||
if city:
|
|
||||||
address.append(normalize(city))
|
|
||||||
if state_province:
|
|
||||||
address.append(normalize(state_province))
|
|
||||||
else:
|
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
address = []
|
||||||
|
if searchtext and searchtext.strip():
|
||||||
|
address.append(normalize(searchtext))
|
||||||
|
if city:
|
||||||
|
address.append(normalize(city))
|
||||||
|
if state_province:
|
||||||
|
address.append(normalize(state_province))
|
||||||
|
|
||||||
country = [country] if country else None
|
country = [country] if country else None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -10,7 +10,7 @@ from setuptools import setup, find_packages
|
|||||||
setup(
|
setup(
|
||||||
name='cartodb_services',
|
name='cartodb_services',
|
||||||
|
|
||||||
version='0.17.4',
|
version='0.17.5',
|
||||||
|
|
||||||
description='CartoDB Services API Python Library',
|
description='CartoDB Services API Python Library',
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user