@@ -19,22 +19,25 @@ language_support = True
19number_of_results = 10
19number_of_results = 10
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}'
23result_base_url = 'https://openstreetmap.org/{osm_type}/{osm_id}'
24result_base_url = 'https://openstreetmap.org/{osm_type}/{osm_id}'
26# do search-request
27# do search-request
27def request(query, params):
28def request(query, params):
29+ params['url'] = base_url +\
28− params['url'] = search_url.format(query=urlencode({'q': query}),
30+ search_string.format(query=urlencode({'q': query}),
29− limit=number_of_results)
31+ limit=number_of_results)
31 if params['language'] != 'all':
33 if params['language'] != 'all':
34+ params['url'] = params['url'] +\
32− params['url'] = params['url'] + "&lang=" + params['language'].replace('_', '-')
35+ "&lang=" + params['language'].replace('_', '-')
34 # using searx User-Agent
37 # using searx User-Agent
35 params['headers']['User-Agent'] = searx_useragent()
38 params['headers']['User-Agent'] = searx_useragent()
37− # FIX: SSLError: [Errno 1] _ssl.c:510: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
40+ # FIX: SSLError: SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
38 params['verify'] = False
41 params['verify'] = False
40 return params
43 return params
@@ -47,15 +50,15 @@ def response(resp):
48 # parse results
51 # parse results
49 for r in json.get('features', {}):
52 for r in json.get('features', {}):
51 properties = r.get('properties')
54 properties = r.get('properties')
53 if not properties:
56 if not properties:
56 # get title
59 # get title
57 title = properties['name']
60 title = properties['name']
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,7 +69,7 @@ def response(resp):
67 # continue if invalide osm-type
70 # continue if invalide osm-type
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'))
@@ -74,14 +77,20 @@ def response(resp):
74 'id': properties.get('osm_id')}
77 'id': properties.get('osm_id')}
76 geojson = r.get('geometry')
79 geojson = r.get('geometry')
78− if properties.get('extent'):
81+ if properties.get('extent'):
79− boundingbox = [properties.get('extent')[3], properties.get('extent')[1], properties.get('extent')[0], properties.get('extent')[2]]
82+ boundingbox = [properties.get('extent')[3],
83+ properties.get('extent')[1],
84+ properties.get('extent')[0],
85+ properties.get('extent')[2]]
81 # TODO: better boundingbox calculation
87 # TODO: better boundingbox calculation
82− boundingbox = [geojson['coordinates'][1], geojson['coordinates'][1], geojson['coordinates'][0], geojson['coordinates'][0]]
88+ boundingbox = [geojson['coordinates'][1],
83−
89+ geojson['coordinates'][1],
90+ geojson['coordinates'][0],
91+ geojson['coordinates'][0]]
84− # TODO: address calculation
93+ # address calculation
85 address = {}
94 address = {}
87 # get name
96 # get name
@@ -90,14 +99,14 @@ def response(resp):
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')}
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',
108+ properties.get('town', # noqa
100− properties.get('village'))),
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')})