|
@@ -19,22 +19,25 @@ language_support = True
|
19
|
19
|
number_of_results = 10
|
20
|
20
|
|
21
|
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
|
24
|
result_base_url = 'https://openstreetmap.org/{osm_type}/{osm_id}'
|
24
|
25
|
|
25
|
26
|
|
26
|
27
|
# do search-request
|
27
|
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
|
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
|
37
|
# using searx User-Agent
|
35
|
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
|
41
|
params['verify'] = False
|
39
|
42
|
|
40
|
43
|
return params
|
|
@@ -47,15 +50,15 @@ def response(resp):
|
47
|
50
|
|
48
|
51
|
# parse results
|
49
|
52
|
for r in json.get('features', {}):
|
50
|
|
-
|
|
53
|
+
|
51
|
54
|
properties = r.get('properties')
|
52
|
|
-
|
|
55
|
+
|
53
|
56
|
if not properties:
|
54
|
57
|
continue
|
55
|
|
-
|
|
58
|
+
|
56
|
59
|
# get title
|
57
|
60
|
title = properties['name']
|
58
|
|
-
|
|
61
|
+
|
59
|
62
|
# get osm-type
|
60
|
63
|
if properties.get('osm_type') == 'N':
|
61
|
64
|
osm_type = 'node'
|
|
@@ -66,7 +69,7 @@ def response(resp):
|
66
|
69
|
else:
|
67
|
70
|
# continue if invalide osm-type
|
68
|
71
|
continue
|
69
|
|
-
|
|
72
|
+
|
70
|
73
|
url = result_base_url.format(osm_type=osm_type,
|
71
|
74
|
osm_id=properties.get('osm_id'))
|
72
|
75
|
|
|
@@ -74,14 +77,20 @@ def response(resp):
|
74
|
77
|
'id': properties.get('osm_id')}
|
75
|
78
|
|
76
|
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
|
86
|
else:
|
81
|
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
|
94
|
address = {}
|
86
|
95
|
|
87
|
96
|
# get name
|
|
@@ -90,14 +99,14 @@ def response(resp):
|
90
|
99
|
properties.get('osm_key') == 'tourism' or\
|
91
|
100
|
properties.get('osm_key') == 'leisure':
|
92
|
101
|
address = {'name': properties.get('name')}
|
93
|
|
-
|
|
102
|
+
|
94
|
103
|
# add rest of adressdata, if something is already found
|
95
|
104
|
if address.get('name'):
|
96
|
105
|
address.update({'house_number': properties.get('housenumber'),
|
97
|
106
|
'road': properties.get('street'),
|
98
|
107
|
'locality': properties.get('city',
|
99
|
|
- properties.get('town',
|
100
|
|
- properties.get('village'))),
|
|
108
|
+ properties.get('town', # noqa
|
|
109
|
+ properties.get('village'))), # noqa
|
101
|
110
|
'postcode': properties.get('postcode'),
|
102
|
111
|
'country': properties.get('country')})
|
103
|
112
|
else:
|