From 2c6531b2330a5c8ca986379dbad8812a6c6d3e49 Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Tue, 9 Jun 2020 17:01:59 +0200 Subject: [PATCH 1/5] [enh] add routing directions to osm search - closes #254 --- searx/engines/openstreetmap.py | 14 ++++++++++++++ searx/plugins/self_info.py | 6 ++---- searx/results.py | 4 ++-- searx/templates/legacy/results.html | 8 ++++++-- searx/templates/oscar/results.html | 8 ++++++-- searx/templates/simple/results.html | 10 ++++++++-- 6 files changed, 38 insertions(+), 12 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: diff --git a/searx/plugins/self_info.py b/searx/plugins/self_info.py index 8d6c661ad..67e5e0e53 100644 --- a/searx/plugins/self_info.py +++ b/searx/plugins/self_info.py @@ -37,10 +37,8 @@ def post_search(request, search): ip = x_forwarded_for[0] else: ip = request.remote_addr - search.result_container.answers.clear() - search.result_container.answers.add(ip) + search.result_container.answers['ip'] = {'answer': ip} elif p.match(search.search_query.query): ua = request.user_agent - search.result_container.answers.clear() - search.result_container.answers.add(ua) + search.result_container.answers['user-agent'] = {'answer': ua} return True diff --git a/searx/results.py b/searx/results.py index 62a01a5bd..17db33aa4 100644 --- a/searx/results.py +++ b/searx/results.py @@ -131,7 +131,7 @@ class ResultContainer(object): self._merged_results = [] self.infoboxes = [] self.suggestions = set() - self.answers = set() + self.answers = {} self.corrections = set() self._number_of_results = [] self._ordered = False @@ -146,7 +146,7 @@ class ResultContainer(object): self.suggestions.add(result['suggestion']) results.remove(result) elif 'answer' in result: - self.answers.add(result['answer']) + self.answers[result['answer']] = result results.remove(result) elif 'correction' in result: self.corrections.add(result['correction']) diff --git a/searx/templates/legacy/results.html b/searx/templates/legacy/results.html index 2e28bc91f..fd95657a4 100644 --- a/searx/templates/legacy/results.html +++ b/searx/templates/legacy/results.html @@ -33,8 +33,12 @@ {% if answers %}
{{ _('Answers') }} - {% for answer in answers %} - {{ answer }} + {% for answer in answers.values() %} + {% if answer.url %} + {{ answer.answer }} + {% else %} + {{ answer.answer }} + {% endif %} {% endfor %}
{% endif %} diff --git a/searx/templates/oscar/results.html b/searx/templates/oscar/results.html index fc4efadfa..7a444d19f 100644 --- a/searx/templates/oscar/results.html +++ b/searx/templates/oscar/results.html @@ -94,9 +94,13 @@ {%- endif %} {% if answers -%} - {%- for answer in answers %} + {%- for answer in answers.values() %}
- {{ answer }} + {% if answer.url %} + {{ answer.answer }} + {% else %} + {{ answer.answer }} + {% endif %}
{%- endfor %} {%- endif %} diff --git a/searx/templates/simple/results.html b/searx/templates/simple/results.html index 8885abc30..2e393193f 100644 --- a/searx/templates/simple/results.html +++ b/searx/templates/simple/results.html @@ -15,8 +15,14 @@
{% if answers -%}

{{ _('Answers') }} :

- {%- for answer in answers -%} -
{{- answer -}}
+ {%- for answer in answers.values() -%} +
+ {% if answer.url %} + {{ answer.answer }} + {% else %} + {{ answer.answer }} + {% endif %} +
{%- endfor -%}
{%- endif %} From 6c062862513dcaeebeb497ba1c61ea83e3a9e50b Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Tue, 9 Jun 2020 20:31:51 +0200 Subject: [PATCH 2/5] [enh] add length and author details to youtube videos closes #775 --- searx/engines/youtube_noapi.py | 4 ++++ searx/templates/oscar/result_templates/videos.html | 2 ++ 2 files changed, 6 insertions(+) diff --git a/searx/engines/youtube_noapi.py b/searx/engines/youtube_noapi.py index 49d0ae604..68a3739a2 100644 --- a/searx/engines/youtube_noapi.py +++ b/searx/engines/youtube_noapi.py @@ -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}) diff --git a/searx/templates/oscar/result_templates/videos.html b/searx/templates/oscar/result_templates/videos.html index 3c1913d9d..51ed5a025 100644 --- a/searx/templates/oscar/result_templates/videos.html +++ b/searx/templates/oscar/result_templates/videos.html @@ -16,6 +16,8 @@
{{ result.title|striptags }} {{ result.engine }} + {% if result.author %}

{{ _('Author') }}: {{ result.author }}

{% endif %} + {% if result.length %}

{{ _('Length') }}: {{ result.length }}

{% endif %} {% if result.content %}

{{ result.content|safe }}

{% endif %}
From 29960aa1d912f365846731c9aca166b5b7879d02 Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Tue, 9 Jun 2020 23:49:13 +0200 Subject: [PATCH 3/5] [enh] add official site link to the top of the infobox - closes #1644 --- searx/engines/wikidata.py | 10 ++++++---- searx/templates/oscar/infobox.html | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/searx/engines/wikidata.py b/searx/engines/wikidata.py index e913b3915..9d6238d8b 100644 --- a/searx/engines/wikidata.py +++ b/searx/engines/wikidata.py @@ -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): diff --git a/searx/templates/oscar/infobox.html b/searx/templates/oscar/infobox.html index de595b922..04f2d5f22 100644 --- a/searx/templates/oscar/infobox.html +++ b/searx/templates/oscar/infobox.html @@ -2,6 +2,7 @@
{{- "" -}}

{{ infobox.infobox }}

{{- "" -}} + {% for u in infobox.urls %}{% if u.official %} {{ u.domain }}{% endif %}{% endfor %}
{% if infobox.img_src %}{{ infobox.infobox }}{% endif %} From 43f7b84a59fe60571bb74e1147101f59ca1954eb Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Wed, 10 Jun 2020 00:30:39 +0200 Subject: [PATCH 4/5] [fix] do not stretch images - fixes #1262 --- .../themes/oscar/css/logicodev-dark.css | 5 +++++ .../themes/oscar/css/logicodev-dark.min.css | Bin 13349 -> 13417 bytes searx/static/themes/oscar/css/logicodev.css | 5 +++++ .../static/themes/oscar/css/logicodev.min.css | Bin 9909 -> 9977 bytes .../themes/oscar/less/logicodev/results.less | 6 ++++++ 5 files changed, 16 insertions(+) diff --git a/searx/static/themes/oscar/css/logicodev-dark.css b/searx/static/themes/oscar/css/logicodev-dark.css index b904c6701..b2cf38ba5 100644 --- a/searx/static/themes/oscar/css/logicodev-dark.css +++ b/searx/static/themes/oscar/css/logicodev-dark.css @@ -267,6 +267,11 @@ input[type=checkbox]:not(:checked) + .label_hide_if_checked + .label_hide_if_not outline: 0 none; position: relative; } +@media screen and (max-width: 75em) { + .img-thumbnail { + object-fit: cover; + } +} .infobox .panel-heading { background-color: #f6f9fa; } diff --git a/searx/static/themes/oscar/css/logicodev-dark.min.css b/searx/static/themes/oscar/css/logicodev-dark.min.css index f03e6336ba8ddbf541ac51ab7785af9e7f76570b..603aedfa9a3def13baea1426fb6eb67548f744d8 100644 GIT binary patch delta 80 zcmZ3Q@iJq>CthcV+|-oJM1|tyqSVwpg~YrR1&!Rq3f=O|l#&c9bJNsZ&1${O+;rWN jjMChsyu{3$>indv)Z`M~w9FE#&+{!bqo delta 12 TcmaEvu{2}DC*I9we8y@3D+2{y diff --git a/searx/static/themes/oscar/css/logicodev.css b/searx/static/themes/oscar/css/logicodev.css index b6c4af950..d5a2aa6a9 100644 --- a/searx/static/themes/oscar/css/logicodev.css +++ b/searx/static/themes/oscar/css/logicodev.css @@ -240,6 +240,11 @@ input[type=checkbox]:not(:checked) + .label_hide_if_checked + .label_hide_if_not outline: 0 none; position: relative; } +@media screen and (max-width: 75em) { + .img-thumbnail { + object-fit: cover; + } +} .infobox .panel-heading { background-color: #f6f9fa; } diff --git a/searx/static/themes/oscar/css/logicodev.min.css b/searx/static/themes/oscar/css/logicodev.min.css index a7d750d193a0fcaf1556ad6950cb2bac9e17c316..7f221d5eca4dd5e3063ea6d914ea37bb212992a3 100644 GIT binary patch delta 84 zcmdn$`_p$rJioI;ZfZ(qqC#HFfN=b&5xoK*yX0={sZn|zs nMrm$RUSeiWb$(J-YI2EgT4sq=a(-EAQSIb@eu>Rx{PyAiN2(t` delta 12 TcmezAyVZ9?Jpbm!{9)n%C_Du@ diff --git a/searx/static/themes/oscar/less/logicodev/results.less b/searx/static/themes/oscar/less/logicodev/results.less index a33ca7673..c2279634e 100644 --- a/searx/static/themes/oscar/less/logicodev/results.less +++ b/searx/static/themes/oscar/less/logicodev/results.less @@ -185,3 +185,9 @@ outline: 0 none; position: relative; } + +@media screen and (max-width: 75em) { + .img-thumbnail { + object-fit: cover; + } +} From aa7c043ff40bd1c1ec2e81748627aeac24608580 Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Wed, 10 Jun 2020 00:34:57 +0200 Subject: [PATCH 5/5] [fix] resolve pep8 errors --- searx/engines/openstreetmap.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/searx/engines/openstreetmap.py b/searx/engines/openstreetmap.py index 011523433..257b1a1b3 100644 --- a/searx/engines/openstreetmap.py +++ b/searx/engines/openstreetmap.py @@ -23,7 +23,7 @@ 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_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 (.+)') @@ -41,7 +41,6 @@ def response(resp): results = [] json = loads(resp.text) - if resp.search_params['route']: results.append({ 'answer': gettext('Get directions'),