diff options
author | Adam Tauber <asciimoo@gmail.com> | 2014-09-06 14:09:03 +0200 |
---|---|---|
committer | Adam Tauber <asciimoo@gmail.com> | 2014-09-06 14:09:03 +0200 |
commit | 3319091496c084dbdd9f9b060a83a6052c5fc5cd (patch) | |
tree | 4261bbfe95410e7901dfc75028ae14311d09670a /searx/engines | |
parent | f72255e3427b162459605a3df41b3077a87480dc (diff) | |
download | searxng-3319091496c084dbdd9f9b060a83a6052c5fc5cd.tar.gz searxng-3319091496c084dbdd9f9b060a83a6052c5fc5cd.zip |
[enh] new engine: openstreetmap
Diffstat (limited to 'searx/engines')
-rw-r--r-- | searx/engines/openstreetmap.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/searx/engines/openstreetmap.py b/searx/engines/openstreetmap.py new file mode 100644 index 000000000..ea7251486 --- /dev/null +++ b/searx/engines/openstreetmap.py @@ -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 |