37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
#!/usr/bin/pyhton3
|
|
import requests
|
|
import time
|
|
|
|
|
|
def translate(_input, lang='RU'):
|
|
url = "https://www2.deepl.com/jsonrpc"
|
|
|
|
r = requests.post(
|
|
url,
|
|
json={
|
|
"jsonrpc": "2.0",
|
|
"method": "LMT_handle_jobs",
|
|
"params": {
|
|
"jobs": [{
|
|
"kind": "default",
|
|
"raw_en_sentence": _input,
|
|
"raw_en_context_before": [],
|
|
"raw_en_context_after": [],
|
|
"preferred_num_beams": 4,
|
|
"quality": "fast"
|
|
}],
|
|
"lang": {
|
|
"user_preferred_langs": [lang],
|
|
"source_lang_user_selected": "auto",
|
|
"target_lang": "RU"
|
|
},
|
|
"priority": -1,
|
|
"commonJobParams": {},
|
|
"timestamp": int(round(time.time() * 1000))
|
|
},
|
|
"id": 40890009
|
|
}
|
|
)
|
|
print(r.json())
|
|
return r.json()['result']['translations'][0]['beams'][0]['postprocessed_sentence']
|