瀏覽代碼

google engine :remove OSM map

Dalf 10 年之前
父節點
當前提交
72c8de35a2
共有 1 個檔案被更改,包括 29 行新增50 行删除
  1. 29
    50
      searx/engines/google.py

+ 29
- 50
searx/engines/google.py 查看文件

@@ -282,7 +282,8 @@ def response(resp):
282 282
                 results.append({'url': url,
283 283
                                 'title': title,
284 284
                                 'content': content})
285
-        except:
285
+        except Exception, e:
286
+            print e
286 287
             continue
287 288
 
288 289
     # parse suggestion
@@ -305,7 +306,8 @@ def parse_images(result, google_hostname):
305 306
                         'title': '',
306 307
                         'content': '',
307 308
                         'img_src': img_src,
308
-                        'template': 'images.html'})
309
+                        'template': 'images.html'
310
+                        })
309 311
 
310 312
     return results
311 313
 
@@ -316,12 +318,13 @@ def parse_map_near(parsed_url, x, google_hostname):
316 318
     for result in x:
317 319
         title = extract_text_from_dom(result, map_near_title)
318 320
         url = parse_url(extract_text_from_dom(result, map_near_url), google_hostname)
321
+        attributes = []
319 322
         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
+                        })
325 328
 
326 329
     return results
327 330
 
@@ -335,69 +338,45 @@ def parse_map_detail(parsed_url, result, google_hostname):
335 338
         m = re.search('ll\=([0-9\.]+),([0-9\.]+)\&z\=([0-9]+)', parsed_url.query)
336 339
 
337 340
     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
356 345
 
357 346
         # attributes
358 347
         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)
361 352
 
362 353
         # title / content / url
363 354
         website_title = extract_text_from_dom(result, map_website_title_xpath)
364 355
         content = extract_text_from_dom(result, content_xpath)
365 356
         website_url = parse_url(extract_text_from_dom(result, map_website_url_xpath), google_hostname)
366 357
 
367
-        # add an infobox if there is a website
358
+        # add a result if there is a website
368 359
         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
377 364
                             })
378 365
 
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
-                        })
390 366
     return results
391 367
 
392 368
 
393
-def add_attributes(attributes, name, value):
369
+def add_attributes(attributes, name, value, url):
394 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})
396 372
 
397 373
 
398 374
 def attributes_to_html(attributes):
399 375
     retval = '<table class="table table-striped">'
400 376
     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>'
402 381
     retval = retval + '</table>'
403 382
     return retval