.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.photon Namespace Reference

Functions

 request (query, params)
 
 response (resp)
 

Variables

dict about
 
list categories = ['map']
 
bool paging = False
 
int number_of_results = 10
 
str base_url = 'https://photon.komoot.io/'
 
str search_string = 'api/?{query}&limit={limit}'
 
str result_base_url = 'https://openstreetmap.org/{osm_type}/{osm_id}'
 
list supported_languages = ['de', 'en', 'fr', 'it']
 

Detailed Description

 Photon (Map)

Function Documentation

◆ request()

searx.engines.photon.request ( query,
params )

Definition at line 35 of file photon.py.

35def request(query, params):
36 params['url'] = base_url + search_string.format(query=urlencode({'q': query}), limit=number_of_results)
37
38 if params['language'] != 'all':
39 language = params['language'].split('_')[0]
40 if language in supported_languages:
41 params['url'] = params['url'] + "&lang=" + language
42
43 # using searx User-Agent
44 params['headers']['User-Agent'] = searx_useragent()
45
46 return params
47
48
49# get response from search-request

◆ response()

searx.engines.photon.response ( resp)

Definition at line 50 of file photon.py.

50def response(resp):
51 results = []
52 json = loads(resp.text)
53
54 # parse results
55 for r in json.get('features', {}):
56
57 properties = r.get('properties')
58
59 if not properties:
60 continue
61
62 # get title
63 title = properties.get('name')
64
65 # get osm-type
66 if properties.get('osm_type') == 'N':
67 osm_type = 'node'
68 elif properties.get('osm_type') == 'W':
69 osm_type = 'way'
70 elif properties.get('osm_type') == 'R':
71 osm_type = 'relation'
72 else:
73 # continue if invalid osm-type
74 continue
75
76 url = result_base_url.format(osm_type=osm_type, osm_id=properties.get('osm_id'))
77
78 osm = {'type': osm_type, 'id': properties.get('osm_id')}
79
80 geojson = r.get('geometry')
81
82 if properties.get('extent'):
83 boundingbox = [
84 properties.get('extent')[3],
85 properties.get('extent')[1],
86 properties.get('extent')[0],
87 properties.get('extent')[2],
88 ]
89 else:
90 # better boundingbox calculation?
91 boundingbox = [
92 geojson['coordinates'][1],
93 geojson['coordinates'][1],
94 geojson['coordinates'][0],
95 geojson['coordinates'][0],
96 ]
97
98 # address calculation
99 address = {}
100
101 # get name
102 if (
103 properties.get('osm_key') == 'amenity'
104 or properties.get('osm_key') == 'shop'
105 or properties.get('osm_key') == 'tourism'
106 or properties.get('osm_key') == 'leisure'
107 ):
108 address = {'name': properties.get('name')}
109
110 # add rest of adressdata, if something is already found
111 if address.get('name'):
112 address.update(
113 {
114 'house_number': properties.get('housenumber'),
115 'road': properties.get('street'),
116 'locality': properties.get(
117 'city', properties.get('town', properties.get('village')) # noqa
118 ), # noqa
119 'postcode': properties.get('postcode'),
120 'country': properties.get('country'),
121 }
122 )
123 else:
124 address = None
125
126 # append result
127 results.append(
128 {
129 'template': 'map.html',
130 'title': title,
131 'content': '',
132 'longitude': geojson['coordinates'][0],
133 'latitude': geojson['coordinates'][1],
134 'boundingbox': boundingbox,
135 'geojson': geojson,
136 'address': address,
137 'osm': osm,
138 'url': url,
139 }
140 )
141
142 # return results
143 return results

Variable Documentation

◆ about

dict searx.engines.photon.about
Initial value:
1= {
2 "website": 'https://photon.komoot.io',
3 "wikidata_id": None,
4 "official_api_documentation": 'https://photon.komoot.io/',
5 "use_official_api": True,
6 "require_api_key": False,
7 "results": 'JSON',
8}

Definition at line 11 of file photon.py.

◆ base_url

str searx.engines.photon.base_url = 'https://photon.komoot.io/'

Definition at line 26 of file photon.py.

◆ categories

list searx.engines.photon.categories = ['map']

Definition at line 21 of file photon.py.

◆ number_of_results

int searx.engines.photon.number_of_results = 10

Definition at line 23 of file photon.py.

◆ paging

bool searx.engines.photon.paging = False

Definition at line 22 of file photon.py.

◆ result_base_url

str searx.engines.photon.result_base_url = 'https://openstreetmap.org/{osm_type}/{osm_id}'

Definition at line 28 of file photon.py.

◆ search_string

str searx.engines.photon.search_string = 'api/?{query}&limit={limit}'

Definition at line 27 of file photon.py.

◆ supported_languages

list searx.engines.photon.supported_languages = ['de', 'en', 'fr', 'it']

Definition at line 31 of file photon.py.