Merge branch 'master' into filtron

This commit is contained in:
Markus Heiser 2020-06-10 04:55:41 +00:00 committed by GitHub
commit 4496ad1218
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 68 additions and 18 deletions

View File

@ -10,7 +10,9 @@
@parse url, title @parse url, title
""" """
import re
from json import loads from json import loads
from flask_babel import gettext
# engine dependent config # engine dependent config
categories = ['map'] categories = ['map']
@ -21,10 +23,15 @@ base_url = 'https://nominatim.openstreetmap.org/'
search_string = 'search/{query}?format=json&polygon_geojson=1&addressdetails=1' search_string = 'search/{query}?format=json&polygon_geojson=1&addressdetails=1'
result_base_url = 'https://openstreetmap.org/{osm_type}/{osm_id}' 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 # do search-request
def request(query, params): def request(query, params):
params['url'] = base_url + search_string.format(query=query.decode('utf-8')) params['url'] = base_url + search_string.format(query=query.decode('utf-8'))
params['route'] = route_re.match(query.decode('utf-8'))
return params return params
@ -34,6 +41,12 @@ def response(resp):
results = [] results = []
json = loads(resp.text) 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 # parse results
for r in json: for r in json:
if 'display_name' not in r: if 'display_name' not in r:

View File

@ -414,11 +414,13 @@ def add_url(urls, result, id_cache, property_id=None, default_label=None, url_pr
# append urls # append urls
for url in links: for url in links:
if url is not None: if url is not None:
urls.append({'title': default_label or label, u = {'title': default_label or label, 'url': url}
'url': url}) if property_id == 'P856':
u['official'] = True
u['domain'] = url.split('/')[2]
urls.append(u)
if results is not None: if results is not None:
results.append({'title': default_label or label, results.append(u)
'url': url})
def get_imdblink(result, url_prefix): def get_imdblink(result, url_prefix):

View File

@ -70,11 +70,15 @@ def response(resp):
title = get_text_from_json(video.get('title', {})) title = get_text_from_json(video.get('title', {}))
content = get_text_from_json(video.get('descriptionSnippet', {})) content = get_text_from_json(video.get('descriptionSnippet', {}))
embedded = embedded_url.format(videoid=videoid) embedded = embedded_url.format(videoid=videoid)
author = get_text_from_json(video.get('ownerText', {}))
length = get_text_from_json(video.get('lengthText', {}))
# append result # append result
results.append({'url': url, results.append({'url': url,
'title': title, 'title': title,
'content': content, 'content': content,
'author': author,
'length': length,
'template': 'videos.html', 'template': 'videos.html',
'embedded': embedded, 'embedded': embedded,
'thumbnail': thumbnail}) 'thumbnail': thumbnail})

View File

@ -37,10 +37,8 @@ def post_search(request, search):
ip = x_forwarded_for[0] ip = x_forwarded_for[0]
else: else:
ip = request.remote_addr ip = request.remote_addr
search.result_container.answers.clear() search.result_container.answers['ip'] = {'answer': ip}
search.result_container.answers.add(ip)
elif p.match(search.search_query.query): elif p.match(search.search_query.query):
ua = request.user_agent ua = request.user_agent
search.result_container.answers.clear() search.result_container.answers['user-agent'] = {'answer': ua}
search.result_container.answers.add(ua)
return True return True

View File

@ -131,7 +131,7 @@ class ResultContainer(object):
self._merged_results = [] self._merged_results = []
self.infoboxes = [] self.infoboxes = []
self.suggestions = set() self.suggestions = set()
self.answers = set() self.answers = {}
self.corrections = set() self.corrections = set()
self._number_of_results = [] self._number_of_results = []
self._ordered = False self._ordered = False
@ -146,7 +146,7 @@ class ResultContainer(object):
self.suggestions.add(result['suggestion']) self.suggestions.add(result['suggestion'])
results.remove(result) results.remove(result)
elif 'answer' in result: elif 'answer' in result:
self.answers.add(result['answer']) self.answers[result['answer']] = result
results.remove(result) results.remove(result)
elif 'correction' in result: elif 'correction' in result:
self.corrections.add(result['correction']) self.corrections.add(result['correction'])

View File

@ -267,6 +267,11 @@ input[type=checkbox]:not(:checked) + .label_hide_if_checked + .label_hide_if_not
outline: 0 none; outline: 0 none;
position: relative; position: relative;
} }
@media screen and (max-width: 75em) {
.img-thumbnail {
object-fit: cover;
}
}
.infobox .panel-heading { .infobox .panel-heading {
background-color: #f6f9fa; background-color: #f6f9fa;
} }

File diff suppressed because one or more lines are too long

View File

@ -240,6 +240,11 @@ input[type=checkbox]:not(:checked) + .label_hide_if_checked + .label_hide_if_not
outline: 0 none; outline: 0 none;
position: relative; position: relative;
} }
@media screen and (max-width: 75em) {
.img-thumbnail {
object-fit: cover;
}
}
.infobox .panel-heading { .infobox .panel-heading {
background-color: #f6f9fa; background-color: #f6f9fa;
} }

File diff suppressed because one or more lines are too long

View File

@ -185,3 +185,9 @@
outline: 0 none; outline: 0 none;
position: relative; position: relative;
} }
@media screen and (max-width: 75em) {
.img-thumbnail {
object-fit: cover;
}
}

View File

@ -33,8 +33,12 @@
{% if answers %} {% if answers %}
<div id="answers"><span>{{ _('Answers') }}</span> <div id="answers"><span>{{ _('Answers') }}</span>
{% for answer in answers %} {% for answer in answers.values() %}
<span>{{ answer }}</span> {% if answer.url %}
<a href="{{ answer.url }}">{{ answer.answer }}</a>
{% else %}
<span>{{ answer.answer }}</span>
{% endif %}
{% endfor %} {% endfor %}
</div> </div>
{% endif %} {% endif %}

View File

@ -2,6 +2,7 @@
<div class="panel panel-default infobox"> <div class="panel panel-default infobox">
<div class="panel-heading">{{- "" -}} <div class="panel-heading">{{- "" -}}
<h4 class="panel-title infobox_part"><bdi>{{ infobox.infobox }}</bdi></h4>{{- "" -}} <h4 class="panel-title infobox_part"><bdi>{{ infobox.infobox }}</bdi></h4>{{- "" -}}
{% for u in infobox.urls %}{% if u.official %} <a href="{{ u.url }}">{{ u.domain }}</a>{% endif %}{% endfor %}
</div> </div>
<div class="panel-body"> <div class="panel-body">
{% if infobox.img_src %}<img class="img-responsive center-block infobox_part" src="{{ image_proxify(infobox.img_src) }}" alt="{{ infobox.infobox }}" />{% endif %} {% if infobox.img_src %}<img class="img-responsive center-block infobox_part" src="{{ image_proxify(infobox.img_src) }}" alt="{{ infobox.infobox }}" />{% endif %}

View File

@ -16,6 +16,8 @@
<div class="container-fluid"> <div class="container-fluid">
<div class="row"> <div class="row">
<a href="{{ result.url }}" {% if results_on_new_tab %}target="_blank" rel="noopener noreferrer"{% else %}rel="noreferrer"{% endif %}><img class="thumbnail col-xs-6 col-sm-4 col-md-4 result-content" src="{{ image_proxify(result.thumbnail) }}" alt="{{ result.title|striptags }} {{ result.engine }}" /></a> <a href="{{ result.url }}" {% if results_on_new_tab %}target="_blank" rel="noopener noreferrer"{% else %}rel="noreferrer"{% endif %}><img class="thumbnail col-xs-6 col-sm-4 col-md-4 result-content" src="{{ image_proxify(result.thumbnail) }}" alt="{{ result.title|striptags }} {{ result.engine }}" /></a>
{% if result.author %}<p class="col-xs-12 col-sm-8 col-md-8 result-content"><b>{{ _('Author') }}</b>: {{ result.author }}</p>{% endif %}
{% if result.length %}<p class="col-xs-12 col-sm-8 col-md-8 result-content"><b>{{ _('Length') }}</b>: {{ result.length }}</p>{% endif %}
{% if result.content %}<p class="col-xs-12 col-sm-8 col-md-8 result-content">{{ result.content|safe }}</p>{% endif %} {% if result.content %}<p class="col-xs-12 col-sm-8 col-md-8 result-content">{{ result.content|safe }}</p>{% endif %}
</div> </div>
</div> </div>

View File

@ -94,9 +94,13 @@
{%- endif %} {%- endif %}
{% if answers -%} {% if answers -%}
{%- for answer in answers %} {%- for answer in answers.values() %}
<div class="result well"> <div class="result well">
<span>{{ answer }}</span> {% if answer.url %}
<a href="{{ answer.url }}">{{ answer.answer }}</a>
{% else %}
<span>{{ answer.answer }}</span>
{% endif %}
</div> </div>
{%- endfor %} {%- endfor %}
{%- endif %} {%- endif %}

View File

@ -15,8 +15,14 @@
<div id="results" class="{{ only_template }}"> <div id="results" class="{{ only_template }}">
{% if answers -%} {% if answers -%}
<div id="answers"><h4 class="title">{{ _('Answers') }} : </h4> <div id="answers"><h4 class="title">{{ _('Answers') }} : </h4>
{%- for answer in answers -%} {%- for answer in answers.values() -%}
<div class="answer">{{- answer -}}</div> <div class="answer">
{% if answer.url %}
<a href="{{ answer.url }}">{{ answer.answer }}</a>
{% else %}
<span>{{ answer.answer }}</span>
{% endif %}
</div>
{%- endfor -%} {%- endfor -%}
</div> </div>
{%- endif %} {%- endif %}