Browse Source

[fix] pep8

Thomas Pointhuber 10 years ago
parent
commit
672f1c674c
2 changed files with 34 additions and 24 deletions
  1. 5
    4
      searx/engines/openstreetmap.py
  2. 29
    20
      searx/engines/photon.py

+ 5
- 4
searx/engines/openstreetmap.py View File

16
 paging = False
16
 paging = False
17
 
17
 
18
 # search-url
18
 # search-url
19
-base_url = 'https://nominatim.openstreetmap.org/search/{query}?format=json&polygon_geojson=1&addressdetails=1'
19
+base_url = 'https://nominatim.openstreetmap.org/'
20
+search_string = 'search/{query}?format=json&polygon_geojson=1&addressdetails=1'
20
 result_base_url = 'https://openstreetmap.org/{osm_type}/{osm_id}'
21
 result_base_url = 'https://openstreetmap.org/{osm_type}/{osm_id}'
21
 
22
 
22
 
23
 
23
 # do search-request
24
 # do search-request
24
 def request(query, params):
25
 def request(query, params):
25
-    params['url'] = base_url.format(query=query)
26
+    params['url'] = base_url + search_string.format(query=query)
26
 
27
 
27
     # using searx User-Agent
28
     # using searx User-Agent
28
     params['headers']['User-Agent'] = searx_useragent()
29
     params['headers']['User-Agent'] = searx_useragent()
71
             address.update({'house_number': address_raw.get('house_number'),
72
             address.update({'house_number': address_raw.get('house_number'),
72
                            'road': address_raw.get('road'),
73
                            'road': address_raw.get('road'),
73
                            'locality': address_raw.get('city',
74
                            'locality': address_raw.get('city',
74
-                                       address_raw.get('town',
75
-                                       address_raw.get('village'))),
75
+                                       address_raw.get('town',          # noqa
76
+                                       address_raw.get('village'))),    # noqa
76
                            'postcode': address_raw.get('postcode'),
77
                            'postcode': address_raw.get('postcode'),
77
                            'country': address_raw.get('country'),
78
                            'country': address_raw.get('country'),
78
                            'country_code': address_raw.get('country_code')})
79
                            'country_code': address_raw.get('country_code')})

+ 29
- 20
searx/engines/photon.py View File

19
 number_of_results = 10
19
 number_of_results = 10
20
 
20
 
21
 # search-url
21
 # search-url
22
-search_url = 'https://photon.komoot.de/api/?{query}&limit={limit}'
22
+base_url = 'https://photon.komoot.de/'
23
+search_string = 'api/?{query}&limit={limit}'
23
 result_base_url = 'https://openstreetmap.org/{osm_type}/{osm_id}'
24
 result_base_url = 'https://openstreetmap.org/{osm_type}/{osm_id}'
24
 
25
 
25
 
26
 
26
 # do search-request
27
 # do search-request
27
 def request(query, params):
28
 def request(query, params):
28
-    params['url'] = search_url.format(query=urlencode({'q': query}),
29
-                                      limit=number_of_results)
29
+    params['url'] = base_url +\
30
+        search_string.format(query=urlencode({'q': query}),
31
+                             limit=number_of_results)
30
 
32
 
31
     if params['language'] != 'all':
33
     if params['language'] != 'all':
32
-        params['url'] = params['url'] + "&lang=" + params['language'].replace('_', '-')
34
+        params['url'] = params['url'] +\
35
+            "&lang=" + params['language'].replace('_', '-')
33
 
36
 
34
     # using searx User-Agent
37
     # using searx User-Agent
35
     params['headers']['User-Agent'] = searx_useragent()
38
     params['headers']['User-Agent'] = searx_useragent()
36
-    
37
-    # FIX: SSLError: [Errno 1] _ssl.c:510: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
39
+
40
+    # FIX: SSLError: SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
38
     params['verify'] = False
41
     params['verify'] = False
39
 
42
 
40
     return params
43
     return params
47
 
50
 
48
     # parse results
51
     # parse results
49
     for r in json.get('features', {}):
52
     for r in json.get('features', {}):
50
-    
53
+
51
         properties = r.get('properties')
54
         properties = r.get('properties')
52
-        
55
+
53
         if not properties:
56
         if not properties:
54
             continue
57
             continue
55
-        
58
+
56
         # get title
59
         # get title
57
         title = properties['name']
60
         title = properties['name']
58
-        
61
+
59
         # get osm-type
62
         # get osm-type
60
         if properties.get('osm_type') == 'N':
63
         if properties.get('osm_type') == 'N':
61
             osm_type = 'node'
64
             osm_type = 'node'
66
         else:
69
         else:
67
             # continue if invalide osm-type
70
             # continue if invalide osm-type
68
             continue
71
             continue
69
-            
72
+
70
         url = result_base_url.format(osm_type=osm_type,
73
         url = result_base_url.format(osm_type=osm_type,
71
                                      osm_id=properties.get('osm_id'))
74
                                      osm_id=properties.get('osm_id'))
72
 
75
 
74
                'id': properties.get('osm_id')}
77
                'id': properties.get('osm_id')}
75
 
78
 
76
         geojson = r.get('geometry')
79
         geojson = r.get('geometry')
77
-        
78
-        if  properties.get('extent'):
79
-            boundingbox = [properties.get('extent')[3], properties.get('extent')[1], properties.get('extent')[0], properties.get('extent')[2]]
80
+
81
+        if properties.get('extent'):
82
+            boundingbox = [properties.get('extent')[3],
83
+                           properties.get('extent')[1],
84
+                           properties.get('extent')[0],
85
+                           properties.get('extent')[2]]
80
         else:
86
         else:
81
             # TODO: better boundingbox calculation
87
             # TODO: better boundingbox calculation
82
-            boundingbox = [geojson['coordinates'][1], geojson['coordinates'][1], geojson['coordinates'][0], geojson['coordinates'][0]]
83
-        
84
-        # TODO: address calculation
88
+            boundingbox = [geojson['coordinates'][1],
89
+                           geojson['coordinates'][1],
90
+                           geojson['coordinates'][0],
91
+                           geojson['coordinates'][0]]
92
+
93
+        # address calculation
85
         address = {}
94
         address = {}
86
 
95
 
87
         # get name
96
         # get name
90
            properties.get('osm_key') == 'tourism' or\
99
            properties.get('osm_key') == 'tourism' or\
91
            properties.get('osm_key') == 'leisure':
100
            properties.get('osm_key') == 'leisure':
92
             address = {'name': properties.get('name')}
101
             address = {'name': properties.get('name')}
93
-                
102
+
94
         # add rest of adressdata, if something is already found
103
         # add rest of adressdata, if something is already found
95
         if address.get('name'):
104
         if address.get('name'):
96
             address.update({'house_number': properties.get('housenumber'),
105
             address.update({'house_number': properties.get('housenumber'),
97
                            'road': properties.get('street'),
106
                            'road': properties.get('street'),
98
                            'locality': properties.get('city',
107
                            'locality': properties.get('city',
99
-                                       properties.get('town',
100
-                                       properties.get('village'))),
108
+                                       properties.get('town',           # noqa
109
+                                       properties.get('village'))),     # noqa
101
                            'postcode': properties.get('postcode'),
110
                            'postcode': properties.get('postcode'),
102
                            'country': properties.get('country')})
111
                            'country': properties.get('country')})
103
         else:
112
         else: