@@ -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: