mirror of
https://github.com/searxng/searxng.git
synced 2024-11-22 20:17:45 +01:00
[enh] new engine: openstreetmap
This commit is contained in:
parent
f72255e342
commit
3319091496
47
searx/engines/openstreetmap.py
Normal file
47
searx/engines/openstreetmap.py
Normal file
@ -0,0 +1,47 @@
|
||||
## OpenStreetMap (Map)
|
||||
#
|
||||
# @website https://openstreetmap.org/
|
||||
# @provide-api yes (http://wiki.openstreetmap.org/wiki/Nominatim)
|
||||
#
|
||||
# @using-api yes
|
||||
# @results JSON
|
||||
# @stable yes
|
||||
# @parse url, title
|
||||
|
||||
from json import loads
|
||||
|
||||
# engine dependent config
|
||||
categories = ['map']
|
||||
paging = False
|
||||
|
||||
# search-url
|
||||
url = 'https://nominatim.openstreetmap.org/search/{query}?format=json'
|
||||
|
||||
result_base_url = 'https://openstreetmap.org/{osm_type}/{osm_id}'
|
||||
|
||||
|
||||
# do search-request
|
||||
def request(query, params):
|
||||
params['url'] = url.format(query=query)
|
||||
|
||||
return params
|
||||
|
||||
|
||||
# get response from search-request
|
||||
def response(resp):
|
||||
results = []
|
||||
json = loads(resp.text)
|
||||
|
||||
# parse results
|
||||
for r in json:
|
||||
title = r['display_name']
|
||||
osm_type = r.get('osm_type', r.get('type'))
|
||||
url = result_base_url.format(osm_type=osm_type,
|
||||
osm_id=r['osm_id'])
|
||||
# append result
|
||||
results.append({'title': title,
|
||||
'content': '',
|
||||
'url': url})
|
||||
|
||||
# return results
|
||||
return results
|
Loading…
Reference in New Issue
Block a user