mirror of
https://github.com/searxng/searxng.git
synced 2025-08-03 10:32:21 +02:00
Merge branch 'master' into gigablast
This commit is contained in:
commit
ee0da61cbb
15 changed files with 68 additions and 18 deletions
|
@ -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' # noqa
|
||||
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,12 @@ 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:
|
||||
|
|
|
@ -414,11 +414,13 @@ def add_url(urls, result, id_cache, property_id=None, default_label=None, url_pr
|
|||
# append urls
|
||||
for url in links:
|
||||
if url is not None:
|
||||
urls.append({'title': default_label or label,
|
||||
'url': url})
|
||||
u = {'title': default_label or label, 'url': url}
|
||||
if property_id == 'P856':
|
||||
u['official'] = True
|
||||
u['domain'] = url.split('/')[2]
|
||||
urls.append(u)
|
||||
if results is not None:
|
||||
results.append({'title': default_label or label,
|
||||
'url': url})
|
||||
results.append(u)
|
||||
|
||||
|
||||
def get_imdblink(result, url_prefix):
|
||||
|
|
|
@ -70,11 +70,15 @@ def response(resp):
|
|||
title = get_text_from_json(video.get('title', {}))
|
||||
content = get_text_from_json(video.get('descriptionSnippet', {}))
|
||||
embedded = embedded_url.format(videoid=videoid)
|
||||
author = get_text_from_json(video.get('ownerText', {}))
|
||||
length = get_text_from_json(video.get('lengthText', {}))
|
||||
|
||||
# append result
|
||||
results.append({'url': url,
|
||||
'title': title,
|
||||
'content': content,
|
||||
'author': author,
|
||||
'length': length,
|
||||
'template': 'videos.html',
|
||||
'embedded': embedded,
|
||||
'thumbnail': thumbnail})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue