@@ -0,0 +1,121 @@
3+# @website https://photon.komoot.de
4+# @provide-api yes (https://photon.komoot.de/)
11+from urllib import urlencode
12+from json import loads
13+from searx.utils import searx_useragent
15+# engine dependent config
18+language_support = True
19+number_of_results = 10
22+search_url = 'https://photon.komoot.de/api/?{query}&limit={limit}'
23+result_base_url = 'https://openstreetmap.org/{osm_type}/{osm_id}'
27+def request(query, params):
28+ params['url'] = search_url.format(query=urlencode({'q': query}),
29+ limit=number_of_results)
31+ if params['language'] != 'all':
32+ params['url'] = params['url'] + "&lang=" + params['language'].replace('_', '-')
34+ # using searx User-Agent
35+ 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
38+ params['verify'] = False
43+# get response from search-request
46+ json = loads(resp.text)
49+ for r in json.get('features', {}):
51+ properties = r.get('properties')
57+ title = properties['name']
60+ if properties.get('osm_type') == 'N':
62+ elif properties.get('osm_type') == 'W':
64+ elif properties.get('osm_type') == 'R':
65+ osm_type = 'relation'
67+ # continue if invalide osm-type
70+ url = result_base_url.format(osm_type=osm_type,
71+ osm_id=properties.get('osm_id'))
73+ osm = {'type': osm_type,
74+ 'id': properties.get('osm_id')}
76+ geojson = r.get('geometry')
78+ if properties.get('extent'):
79+ boundingbox = [properties.get('extent')[3], properties.get('extent')[1], properties.get('extent')[0], properties.get('extent')[2]]
81+ # TODO: better boundingbox calculation
82+ boundingbox = [geojson['coordinates'][1], geojson['coordinates'][1], geojson['coordinates'][0], geojson['coordinates'][0]]
84+ # TODO: address calculation
88+ if properties.get('osm_key') == 'amenity' or\
89+ properties.get('osm_key') == 'shop' or\
90+ properties.get('osm_key') == 'tourism' or\
91+ properties.get('osm_key') == 'leisure':
92+ address = {'name': properties.get('name')}
94+ # add rest of adressdata, if something is already found
95+ if address.get('name'):
96+ address.update({'house_number': properties.get('housenumber'),
97+ 'road': properties.get('street'),
98+ 'locality': properties.get('city',
99+ properties.get('town',
100+ properties.get('village'))),
101+ 'postcode': properties.get('postcode'),
102+ 'country': properties.get('country')})
107+ results.append({'template': 'map.html',
110+ 'longitude': geojson['coordinates'][0],
111+ 'latitude': geojson['coordinates'][1],
112+ 'boundingbox': boundingbox,
118+ print r['properties']['name']