Compare commits
5 Commits
python-0.1
...
python-0.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
39c54f3e0c | ||
|
|
54e40645fa | ||
|
|
a86b8e86f9 | ||
|
|
8674dabeb2 | ||
|
|
080a386b8f |
7
NEWS.md
7
NEWS.md
@@ -1,3 +1,10 @@
|
|||||||
|
|
||||||
|
February 13th, 2018
|
||||||
|
==================
|
||||||
|
* Version `0.16.7` of the python library
|
||||||
|
* Pick the first result when Mapbox geocoder returns multiple results #462
|
||||||
|
* Normalize input for Mapbox geocoder #462
|
||||||
|
|
||||||
February 12th, 2018
|
February 12th, 2018
|
||||||
==================
|
==================
|
||||||
* Version `0.16.6` of the python library
|
* Version `0.16.6` of the python library
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from mapbox import Geocoder
|
|||||||
from cartodb_services.metrics import Traceable
|
from cartodb_services.metrics import Traceable
|
||||||
from cartodb_services.tools.exceptions import ServiceException
|
from cartodb_services.tools.exceptions import ServiceException
|
||||||
from cartodb_services.tools.qps import qps_retry
|
from cartodb_services.tools.qps import qps_retry
|
||||||
|
from cartodb_services.tools.normalize import normalize
|
||||||
|
|
||||||
GEOCODER_NAME = 'geocoder_name'
|
GEOCODER_NAME = 'geocoder_name'
|
||||||
EPHEMERAL_GEOCODER = 'mapbox.places'
|
EPHEMERAL_GEOCODER = 'mapbox.places'
|
||||||
@@ -39,10 +40,16 @@ class MapboxGeocoder(Traceable):
|
|||||||
def _parse_geocoder_response(self, response):
|
def _parse_geocoder_response(self, response):
|
||||||
json_response = json.loads(response)
|
json_response = json.loads(response)
|
||||||
|
|
||||||
if json_response and json_response[ENTRY_FEATURES]:
|
# If Mapbox returns more that one result, take the first one
|
||||||
feature = json_response[ENTRY_FEATURES][0]
|
if json_response:
|
||||||
|
if type(json_response) == list:
|
||||||
|
json_response = json_response[0]
|
||||||
|
|
||||||
return self._extract_lng_lat_from_feature(feature)
|
if json_response[ENTRY_FEATURES]:
|
||||||
|
feature = json_response[ENTRY_FEATURES][0]
|
||||||
|
return self._extract_lng_lat_from_feature(feature)
|
||||||
|
else:
|
||||||
|
return []
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@@ -61,11 +68,11 @@ class MapboxGeocoder(Traceable):
|
|||||||
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 searchtext and searchtext.strip():
|
||||||
address = [searchtext]
|
address = [normalize(searchtext)]
|
||||||
if city:
|
if city:
|
||||||
address.append(city)
|
address.append(normalize(city))
|
||||||
if state_province:
|
if state_province:
|
||||||
address.append(state_province)
|
address.append(normalize(state_province))
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
def normalize(str_input):
|
||||||
|
return str_input.replace('"', '"') \
|
||||||
|
.replace(';', ',')
|
||||||
@@ -10,7 +10,7 @@ from setuptools import setup, find_packages
|
|||||||
setup(
|
setup(
|
||||||
name='cartodb_services',
|
name='cartodb_services',
|
||||||
|
|
||||||
version='0.16.6',
|
version='0.16.7',
|
||||||
|
|
||||||
description='CartoDB Services API Python Library',
|
description='CartoDB Services API Python Library',
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,11 @@ class MapboxGeocoderTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
assert place
|
assert place
|
||||||
|
|
||||||
|
def test_odd_characters(self):
|
||||||
|
place = self.geocoder.geocode(searchtext='Barcelona; "Spain"')
|
||||||
|
|
||||||
|
assert place
|
||||||
|
|
||||||
def test_empty_request(self):
|
def test_empty_request(self):
|
||||||
place = self.geocoder.geocode(searchtext='', country=None, city=None, state_province=None)
|
place = self.geocoder.geocode(searchtext='', country=None, city=None, state_province=None)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user