diff options
author | Adam Tauber <asciimoo@gmail.com> | 2020-06-09 17:01:59 +0200 |
---|---|---|
committer | Adam Tauber <asciimoo@gmail.com> | 2020-06-09 17:18:44 +0200 |
commit | 2c6531b2330a5c8ca986379dbad8812a6c6d3e49 (patch) | |
tree | 479755fab6b8eda840f55e9b0bb6aabc1256176d /searx/engines/openstreetmap.py | |
parent | 785f0938fdc6c0b587d5f416f005ab5046260ba6 (diff) | |
download | searxng-2c6531b2330a5c8ca986379dbad8812a6c6d3e49.tar.gz searxng-2c6531b2330a5c8ca986379dbad8812a6c6d3e49.zip |
[enh] add routing directions to osm search - closes #254
Diffstat (limited to 'searx/engines/openstreetmap.py')
-rw-r--r-- | searx/engines/openstreetmap.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/searx/engines/openstreetmap.py b/searx/engines/openstreetmap.py index cec10a3c7..011523433 100644 --- a/searx/engines/openstreetmap.py +++ b/searx/engines/openstreetmap.py @@ -10,7 +10,9 @@ @parse url, title """ +import re from json import loads +from flask_babel import gettext # engine dependent config categories = ['map'] @@ -21,10 +23,15 @@ base_url = 'https://nominatim.openstreetmap.org/' search_string = 'search/{query}?format=json&polygon_geojson=1&addressdetails=1' result_base_url = 'https://openstreetmap.org/{osm_type}/{osm_id}' +route_url = 'https://graphhopper.com/maps/?point={}&point={}&locale=en-US&vehicle=car&weighting=fastest&turn_costs=true&use_miles=false&layer=Omniscale' +route_re = re.compile('(?:from )?(.+) to (.+)') + # do search-request def request(query, params): + params['url'] = base_url + search_string.format(query=query.decode('utf-8')) + params['route'] = route_re.match(query.decode('utf-8')) return params @@ -34,6 +41,13 @@ def response(resp): results = [] json = loads(resp.text) + + if resp.search_params['route']: + results.append({ + 'answer': gettext('Get directions'), + 'url': route_url.format(*resp.search_params['route'].groups()), + }) + # parse results for r in json: if 'display_name' not in r: |