on master help sign in
google engine :remove OSM map
commit72c8de35a29f3c58785282d8ca23e33506e01122 authorDalf <alex@al-f.net> dateFri 5 Jun 2015, 23:56 (11 years ago) parentb8fc531
1 file changed+29−50
searx/engines/google.py+29−50
searx/engines/google.py+29−50
@@ -282,7 +282,8 @@ def response(resp):
282282 results.append({'url': url,
283283 'title': title,
284284 'content': content})
285− except:
285+ except Exception, e:
286+ print e
286287 continue
287288
288289 # parse suggestion
@@ -305,7 +306,8 @@ def parse_images(result, google_hostname):
305306 'title': '',
306307 'content': '',
307308 'img_src': img_src,
308− 'template': 'images.html'})
309+ 'template': 'images.html'
310+ })
309311
310312 return results
311313
@@ -316,12 +318,13 @@ def parse_map_near(parsed_url, x, google_hostname):
316318 for result in x:
317319 title = extract_text_from_dom(result, map_near_title)
318320 url = parse_url(extract_text_from_dom(result, map_near_url), google_hostname)
321+ attributes = []
319322 phone = extract_text_from_dom(result, map_near_phone)
320− if phone is not None:
321− phone = property_phone + ": " + phone
322− results.append({'url': url,
323− 'title': title,
324− 'content': phone})
323+ add_attributes(attributes, property_phone, phone, 'tel:' + phone)
324+ results.append({'title': title,
325+ 'url': url,
326+ 'content': attributes_to_html(attributes)
327+ })
325328
326329 return results
327330
@@ -335,69 +338,45 @@ def parse_map_detail(parsed_url, result, google_hostname):
335338 m = re.search('ll\=([0-9\.]+),([0-9\.]+)\&z\=([0-9]+)', parsed_url.query)
336339
337340 if m is not None:
338− # geoloc found
339− lon = float(m.group(2))
340− lat = float(m.group(1))
341− zoom = int(m.group(3))
342−
343− # TODO : map zoom to dlon / dlat
344− dlon = 0.000001
345− dlat = 0.000001
346−
347− boundingbox = [round(lat - dlat, 7), round(lat + dlat, 7), round(lon - dlon, 7), round(lon + dlon, 7)]
348− map_url = url_map\
349− .replace('{latitude}', str(lat))\
350− .replace('{longitude}', str(lon))\
351− .replace('{zoom}', str(zoom+2))
352−
353− geojson = {u'type': u'Point',
354− u'coordinates': [lon, lat]
355− }
341+ # geoloc found (ignored)
342+ lon = float(m.group(2)) # noqa
343+ lat = float(m.group(1)) # noqa
344+ zoom = int(m.group(3)) # noqa
356345
357346 # attributes
358347 attributes = []
359− add_attributes(attributes, property_address, extract_text_from_dom(result, map_address_xpath))
360− add_attributes(attributes, property_phone, extract_text_from_dom(result, map_phone_xpath))
348+ address = extract_text_from_dom(result, map_address_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)
361352
362353 # title / content / url
363354 website_title = extract_text_from_dom(result, map_website_title_xpath)
364355 content = extract_text_from_dom(result, content_xpath)
365356 website_url = parse_url(extract_text_from_dom(result, map_website_url_xpath), google_hostname)
366357
367− # add an infobox if there is a website
358+ # add a result if there is a website
368359 if website_url is not None:
369− results.append({'infobox': website_title,
370− 'id': website_url,
371− 'content': content,
372− 'attributes': attributes,
373− 'urls': [
374− {'title': url_get_label(website_url), 'url': website_url},
375− {'title': property_location, 'url': map_url}
376− ]
360+ results.append({'title': website_title,
361+ 'content': (content + '<br />' if content is not None else '')
362+ + attributes_to_html(attributes),
363+ 'url': website_url
377364 })
378365
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),
384− 'longitude': lon,
385− 'latitude': lat,
386− 'boundingbox': boundingbox,
387− 'geojson': geojson,
388− 'url': website_url if website_url is not None else map_url
389− })
390366 return results
391367
392368
393−def add_attributes(attributes, name, value):
369+def add_attributes(attributes, name, value, url):
394370 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})
396372
397373
398374def attributes_to_html(attributes):
399375 retval = '<table class="table table-striped">'
400376 for a in attributes:
401− retval = retval + '<tr><th>' + a.get('label') + '</th><td>' + a.get('value') + '</td></tr>'
377+ value = a.get('value')
378+ if 'url' in a:
379+ value = '<a href="' + a.get('url') + '">' + value + '</a>'
380+ retval = retval + '<tr><th>' + a.get('label') + '</th><td>' + value + '</td></tr>'
402381 retval = retval + '</table>'
403382 return retval