mirror of
https://github.com/searxng/searxng.git
synced 2024-05-23 05:48:05 +00:00
86b4d2f2d0
We have been using a static type checker (pyright) for a long time, but its check was not yet a prerequisite for passing the quality gate. It was checked in the CI, but the error messages were only logged. As is always the case in life, with checks that you have to do but which have no consequences; you neglect them :-) We didn't activate the checks back then because we (even today) have too much monkey patching in our code (not only in the engines, httpx and others objects are also affected). We want to replace monkey patching with clear interfaces for a long time, the basis for this is increased typing and we can only achieve this if we make type checking an integral part of the quality gate. This PR activates the type check; in order to pass the check, a few typings were corrected in the code, but most type inconsistencies were deactivated via inline comments. This was particularly necessary in places where the code uses properties that stick to the objects (monkey patching). The sticking of properties only happens in a few places, but the access to these properties extends over the entire code, which is why there are many `# type: ignore` markers in the code ... which we will hopefully be able to remove again successively in the future. Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
76 lines
2.1 KiB
Python
76 lines
2.1 KiB
Python
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
"""INA (Videos)
|
|
|
|
"""
|
|
|
|
from html import unescape
|
|
from urllib.parse import urlencode
|
|
from lxml import html
|
|
from searx.utils import extract_text, eval_xpath, eval_xpath_list, eval_xpath_getindex
|
|
|
|
# about
|
|
about = {
|
|
"website": 'https://www.ina.fr/',
|
|
"wikidata_id": 'Q1665109',
|
|
"official_api_documentation": None,
|
|
"use_official_api": False,
|
|
"require_api_key": False,
|
|
"results": 'HTML',
|
|
"language": 'fr',
|
|
}
|
|
|
|
# engine dependent config
|
|
categories = ['videos']
|
|
paging = True
|
|
page_size = 12
|
|
|
|
# search-url
|
|
base_url = 'https://www.ina.fr'
|
|
search_url = base_url + '/ajax/recherche?{query}&espace=1&sort=pertinence&order=desc&offset={start}&modified=size'
|
|
|
|
# specific xpath variables
|
|
results_xpath = '//div[@id="searchHits"]/div'
|
|
url_xpath = './/a/@href'
|
|
title_xpath = './/div[contains(@class,"title-bloc-small")]'
|
|
content_xpath = './/div[contains(@class,"sous-titre-fonction")]'
|
|
thumbnail_xpath = './/img/@data-src'
|
|
publishedDate_xpath = './/div[contains(@class,"dateAgenda")]'
|
|
|
|
|
|
# do search-request
|
|
def request(query, params):
|
|
params['url'] = search_url.format(start=params['pageno'] * page_size, query=urlencode({'q': query}))
|
|
return params
|
|
|
|
|
|
# get response from search-request
|
|
def response(resp):
|
|
results = []
|
|
|
|
# we get html in a JSON container...
|
|
dom = html.fromstring(resp.text)
|
|
|
|
# parse results
|
|
for result in eval_xpath_list(dom, results_xpath):
|
|
url_relative = eval_xpath_getindex(result, url_xpath, 0)
|
|
url = base_url + url_relative
|
|
title = unescape(extract_text(eval_xpath(result, title_xpath)))
|
|
thumbnail = extract_text(eval_xpath(result, thumbnail_xpath))
|
|
content = extract_text(eval_xpath(result, publishedDate_xpath)) + extract_text(
|
|
eval_xpath(result, content_xpath)
|
|
) # type: ignore
|
|
|
|
# append result
|
|
results.append(
|
|
{
|
|
'url': url,
|
|
'title': title,
|
|
'content': content,
|
|
'template': 'videos.html',
|
|
'thumbnail': thumbnail,
|
|
}
|
|
)
|
|
|
|
# return results
|
|
return results
|