don't fail on requests errors
This commit is contained in:
parent
0bbc66bf8b
commit
d301bc9cd8
|
@ -152,17 +152,21 @@ def get_suggestions(request, cell, user_data, places_data):
|
|||
if city:
|
||||
# get commune tile for the user city
|
||||
maplayer = MapLayer.objects.get(slug='mairie')
|
||||
data_result = requests.get(maplayer.geojson_url, timeout=2,
|
||||
without_user=True, cache_duration=300).json()
|
||||
city_slug = slugify(city)
|
||||
if data_result.get('features'):
|
||||
for feature in data_result['features']:
|
||||
if 'Annexe' in feature['properties']['nom']:
|
||||
continue
|
||||
if city_slug in slugify(feature['properties']['nom']):
|
||||
tile_data.append({'key': maplayer.slug,
|
||||
'properties': feature['properties']})
|
||||
break
|
||||
try:
|
||||
data_result = requests.get(maplayer.geojson_url, timeout=2,
|
||||
without_user=True, cache_duration=300).json()
|
||||
except requests.RequestException:
|
||||
pass
|
||||
else:
|
||||
city_slug = slugify(city)
|
||||
if data_result.get('features'):
|
||||
for feature in data_result['features']:
|
||||
if 'Annexe' in feature['properties']['nom']:
|
||||
continue
|
||||
if city_slug in slugify(feature['properties']['nom']):
|
||||
tile_data.append({'key': maplayer.slug,
|
||||
'properties': feature['properties']})
|
||||
break
|
||||
|
||||
if random.random() < 0.6:
|
||||
tile_data.append({'key': 'airquality'})
|
||||
|
@ -183,8 +187,11 @@ def get_suggestions(request, cell, user_data, places_data):
|
|||
for address in addresses:
|
||||
url = '%s/search?q=%s&accept-language=fr&format=json' % (
|
||||
nominatim_url, urllib2.quote(address.encode('utf-8')))
|
||||
search_result = requests.get(url, timeout=2, without_user=True,
|
||||
cache_duration=300).json()
|
||||
try:
|
||||
search_result = requests.get(url, timeout=2, without_user=True,
|
||||
cache_duration=300).json()
|
||||
except requests.RequestException:
|
||||
continue
|
||||
if not search_result:
|
||||
continue
|
||||
coords.append({'lon': search_result[0]['lon'], 'lat': search_result[0]['lat']})
|
||||
|
@ -194,8 +201,11 @@ def get_suggestions(request, cell, user_data, places_data):
|
|||
lon1, lon2 = float(coord['lon']) - 0.006, float(coord['lon']) + 0.006
|
||||
for maplayer in MapLayer.objects.filter(slug__in=('velov', 'piscine', 'tcl')):
|
||||
url = maplayer.geojson_url + '&BBOX=%s,%s,%s,%s' % (lat1, lon1, lat2, lon2)
|
||||
data_result = requests.get(url, timeout=2, without_user=True,
|
||||
cache_duration=300).json()
|
||||
try:
|
||||
data_result = requests.get(url, timeout=2, without_user=True,
|
||||
cache_duration=300).json()
|
||||
except requests.RequestException:
|
||||
continue
|
||||
if not data_result.get('features'):
|
||||
continue
|
||||
for feature in random.sample(
|
||||
|
|
Loading…
Reference in New Issue