@@ -282,7 +282,8 @@ def response(resp):
282 results.append({'url': url,
282 results.append({'url': url,
283 'title': title,
283 'title': title,
284 'content': content})
284 'content': content})
285− except:
285+ except Exception, e:
288 # parse suggestion
289 # parse suggestion
@@ -305,7 +306,8 @@ def parse_images(result, google_hostname):
305 'title': '',
306 'title': '',
306 'content': '',
307 'content': '',
307 'img_src': img_src,
308 'img_src': img_src,
308− 'template': 'images.html'})
309+ 'template': 'images.html'
310 return results
312 return results
@@ -316,12 +318,13 @@ def parse_map_near(parsed_url, x, google_hostname):
316 for result in x:
318 for result in x:
317 title = extract_text_from_dom(result, map_near_title)
319 title = extract_text_from_dom(result, map_near_title)
318 url = parse_url(extract_text_from_dom(result, map_near_url), google_hostname)
320 url = parse_url(extract_text_from_dom(result, map_near_url), google_hostname)
319 phone = extract_text_from_dom(result, map_near_phone)
322 phone = extract_text_from_dom(result, map_near_phone)
320− if phone is not None:
321− phone = property_phone + ": " + phone
323+ add_attributes(attributes, property_phone, phone, 'tel:' + phone)
322− results.append({'url': url,
324+ results.append({'title': title,
323− 'title': title,
325+ 'url': url,
324− 'content': phone})
326+ 'content': attributes_to_html(attributes)
326 return results
329 return results
@@ -335,69 +338,45 @@ def parse_map_detail(parsed_url, result, google_hostname):
335 m = re.search('ll\=([0-9\.]+),([0-9\.]+)\&z\=([0-9]+)', parsed_url.query)
338 m = re.search('ll\=([0-9\.]+),([0-9\.]+)\&z\=([0-9]+)', parsed_url.query)
337 if m is not None:
340 if m is not None:
338− # geoloc found
341+ # geoloc found (ignored)
339− lon = float(m.group(2))
342+ lon = float(m.group(2)) # noqa
340− lat = float(m.group(1))
343+ lat = float(m.group(1)) # noqa
341− zoom = int(m.group(3))
344+ zoom = int(m.group(3)) # noqa
343− # TODO : map zoom to dlon / dlat
347− boundingbox = [round(lat - dlat, 7), round(lat + dlat, 7), round(lon - dlon, 7), round(lon + dlon, 7)]
349− .replace('{latitude}', str(lat))\
350− .replace('{longitude}', str(lon))\
351− .replace('{zoom}', str(zoom+2))
353− geojson = {u'type': u'Point',
354− u'coordinates': [lon, lat]
357 # attributes
346 # attributes
358 attributes = []
347 attributes = []
359− add_attributes(attributes, property_address, extract_text_from_dom(result, map_address_xpath))
348+ address = extract_text_from_dom(result, map_address_xpath)
360− add_attributes(attributes, property_phone, extract_text_from_dom(result, map_phone_xpath))
349+ phone = extract_text_from_dom(result, map_phone_xpath)
350+ add_attributes(attributes, property_address, address, 'geo:' + str(lat) + ',' + str(lon))
351+ add_attributes(attributes, property_phone, phone, 'tel:' + phone)
362 # title / content / url
353 # title / content / url
363 website_title = extract_text_from_dom(result, map_website_title_xpath)
354 website_title = extract_text_from_dom(result, map_website_title_xpath)
364 content = extract_text_from_dom(result, content_xpath)
355 content = extract_text_from_dom(result, content_xpath)
365 website_url = parse_url(extract_text_from_dom(result, map_website_url_xpath), google_hostname)
356 website_url = parse_url(extract_text_from_dom(result, map_website_url_xpath), google_hostname)
367− # add an infobox if there is a website
358+ # add a result if there is a website
368 if website_url is not None:
359 if website_url is not None:
369− results.append({'infobox': website_title,
360+ results.append({'title': website_title,
371− 'content': content,
361+ 'content': (content + '<br />' if content is not None else '')
372− 'attributes': attributes,
362+ + attributes_to_html(attributes),
373− 'urls': [
363+ 'url': website_url
374− {'title': url_get_label(website_url), 'url': website_url},
375− {'title': property_location, 'url': map_url}
379− # usefull because user can see the map directly into searx
380− results.append({'template': 'map.html',
381− 'title': website_title,
382− 'content': (content + '<br />' if content is not None else '')
383− + attributes_to_html(attributes),
386− 'boundingbox': boundingbox,
388− 'url': website_url if website_url is not None else map_url
390 return results
366 return results
393−def add_attributes(attributes, name, value):
369+def add_attributes(attributes, name, value, url):
394 if value is not None and len(value) > 0:
370 if value is not None and len(value) > 0:
395− attributes.append({'label': name, 'value': value})
371+ attributes.append({'label': name, 'value': value, 'url': url})
398def attributes_to_html(attributes):
374def attributes_to_html(attributes):
399 retval = '<table class="table table-striped">'
375 retval = '<table class="table table-striped">'
400 for a in attributes:
376 for a in attributes:
377+ value = a.get('value')
379+ value = '<a href="' + a.get('url') + '">' + value + '</a>'
401− retval = retval + '<tr><th>' + a.get('label') + '</th><td>' + a.get('value') + '</td></tr>'
380+ retval = retval + '<tr><th>' + a.get('label') + '</th><td>' + value + '</td></tr>'
402 retval = retval + '</table>'
381 retval = retval + '</table>'
403 return retval
382 return retval