.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
deepl.py
Go to the documentation of this file.
1
# SPDX-License-Identifier: AGPL-3.0-or-later
2
"""Deepl translation engine"""
3
4
from
json
import
loads
5
6
about = {
7
"website"
:
'https://deepl.com'
,
8
"wikidata_id"
:
'Q43968444'
,
9
"official_api_documentation"
:
'https://www.deepl.com/docs-api'
,
10
"use_official_api"
:
True
,
11
"require_api_key"
:
True
,
12
"results"
:
'JSON'
,
13
}
14
15
engine_type =
'online_dictionary'
16
categories = [
'general'
,
'translate'
]
17
18
url =
'https://api-free.deepl.com/v2/translate'
19
api_key =
None
20
21
22
def
request
(_query, params):
23
'''pre-request callback
24
25
params<dict>:
26
27
- ``method`` : POST/GET
28
- ``headers``: {}
29
- ``data``: {} # if method == POST
30
- ``url``: ''
31
- ``category``: 'search category'
32
- ``pageno``: 1 # number of the requested page
33
'''
34
35
params[
'url'
] = url
36
params[
'method'
] =
'POST'
37
params[
'data'
] = {
'auth_key'
: api_key,
'text'
: params[
'query'
],
'target_lang'
: params[
'to_lang'
][1]}
38
39
return
params
40
41
42
def
response
(resp):
43
results = []
44
result = loads(resp.text)
45
translations = result[
'translations'
]
46
47
infobox =
"<dl>"
48
49
for
translation
in
translations:
50
infobox += f
"<dd>{translation['text']}</dd>"
51
52
infobox +=
"</dl>"
53
54
results.append({
'answer'
: infobox})
55
56
return
results
searx.engines.deepl.request
request(_query, params)
Definition
deepl.py:22
searx.engines.deepl.response
response(resp)
Definition
deepl.py:42
searxng
searx
engines
deepl.py
Generated on Sat Nov 16 2024 00:10:57 for .oO SearXNG Developer Documentation Oo. by
1.12.0