on master help sign in
[fix] pep8
commit672f1c674ca63b7589c1bc6b0c32caf439bd16db authorThomas Pointhuber <thomas.pointhuber@gmx.at> dateTue 16 Dec 2014, 17:01 (12 years ago) parent4805807
2 files changed+34−24
searx/engines/openstreetmap.py+5−4 searx/engines/photon.py+29−20
searx/engines/openstreetmap.py+5−4
@@ -16,13 +16,14 @@ categories = ['map']
1616paging = False
1717
1818# 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'
2021result_base_url = 'https://openstreetmap.org/{osm_type}/{osm_id}'
2122
2223
2324# do search-request
2425def request(query, params):
25− params['url'] = base_url.format(query=query)
26+ params['url'] = base_url + search_string.format(query=query)
2627
2728 # using searx User-Agent
2829 params['headers']['User-Agent'] = searx_useragent()
@@ -71,8 +72,8 @@ def response(resp):
7172 address.update({'house_number': address_raw.get('house_number'),
7273 'road': address_raw.get('road'),
7374 '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
7677 'postcode': address_raw.get('postcode'),
7778 'country': address_raw.get('country'),
7879 'country_code': address_raw.get('country_code')})
searx/engines/photon.py+29−20
@@ -19,22 +19,25 @@ language_support = True
1919number_of_results = 10
2020
2121# 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}'
2324result_base_url = 'https://openstreetmap.org/{osm_type}/{osm_id}'
2425
2526
2627# do search-request
2728def 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)
3032
3133 if params['language'] != 'all':
32− params['url'] = params['url'] + "&lang=" + params['language'].replace('_', '-')
34+ params['url'] = params['url'] +\
35+ "&lang=" + params['language'].replace('_', '-')
3336
3437 # using searx User-Agent
3538 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
3841 params['verify'] = False
3942
4043 return params
@@ -47,15 +50,15 @@ def response(resp):
4750
4851 # parse results
4952 for r in json.get('features', {}):
50−
53+
5154 properties = r.get('properties')
52−
55+
5356 if not properties:
5457 continue
55−
58+
5659 # get title
5760 title = properties['name']
58−
61+
5962 # get osm-type
6063 if properties.get('osm_type') == 'N':
6164 osm_type = 'node'
@@ -66,7 +69,7 @@ def response(resp):
6669 else:
6770 # continue if invalide osm-type
6871 continue
69−
72+
7073 url = result_base_url.format(osm_type=osm_type,
7174 osm_id=properties.get('osm_id'))
7275
@@ -74,14 +77,20 @@ def response(resp):
7477 'id': properties.get('osm_id')}
7578
7679 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]]
8086 else:
8187 # 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
8594 address = {}
8695
8796 # get name
@@ -90,14 +99,14 @@ def response(resp):
9099 properties.get('osm_key') == 'tourism' or\
91100 properties.get('osm_key') == 'leisure':
92101 address = {'name': properties.get('name')}
93−
102+
94103 # add rest of adressdata, if something is already found
95104 if address.get('name'):
96105 address.update({'house_number': properties.get('housenumber'),
97106 'road': properties.get('street'),
98107 'locality': properties.get('city',
99− properties.get('town',
100− properties.get('village'))),
108+ properties.get('town', # noqa
109+ properties.get('village'))), # noqa
101110 'postcode': properties.get('postcode'),
102111 'country': properties.get('country')})
103112 else: