diff options
| author | Bnyro <bnyro@tutanota.com> | 2024-10-15 15:39:14 +0200 |
|---|---|---|
| committer | Markus Heiser <markus.heiser@darmarIT.de> | 2025-01-28 07:07:08 +0100 |
| commit | 9079d0cac0156139952446f0fdc8b37b94c10756 (patch) | |
| tree | 0164ae5b30d173cda9e60ea8048b16033b2029cc /searx/engines/dictzone.py | |
| parent | 70f1b6500861970f8b9e52fbfe52a1796350ea69 (diff) | |
[refactor] translation engines: common interface
Diffstat (limited to 'searx/engines/dictzone.py')
| -rw-r--r-- | searx/engines/dictzone.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/searx/engines/dictzone.py b/searx/engines/dictzone.py index 4a9c4811e..acd682911 100644 --- a/searx/engines/dictzone.py +++ b/searx/engines/dictzone.py @@ -3,7 +3,6 @@ Dictzone """ -from urllib.parse import urljoin from lxml import html from searx.utils import eval_xpath @@ -33,11 +32,10 @@ def request(query, params): # pylint: disable=unused-argument def response(resp): - results = [] - dom = html.fromstring(resp.text) - for k, result in enumerate(eval_xpath(dom, results_xpath)[1:]): + translations = [] + for result in eval_xpath(dom, results_xpath)[1:]: try: from_result, to_results_raw = eval_xpath(result, './td') except: # pylint: disable=bare-except @@ -49,12 +47,17 @@ def response(resp): if t.strip(): to_results.append(to_result.text_content()) - results.append( + translations.append( { - 'url': urljoin(str(resp.url), '?%d' % k), - 'title': from_result.text_content(), - 'content': '; '.join(to_results), + 'text': f"{from_result.text_content()} - {'; '.join(to_results)}", } ) - return results + if translations: + result = { + 'answer': translations[0]['text'], + 'translations': translations, + 'answer_type': 'translations', + } + + return [result] |