I
I
Irina2019-04-06 21:15:11
Python
Irina, 2019-04-06 21:15:11

How to get multiple translation options via the Yandex.Translate API?

There is a script that perfectly copes with the task of translating text. Tell me how to change the script so that it gives out all the translation options for one word.
For example, the word work has translations - work, work, activity.

import requests

def get_transleat(text):
    url = "https://translate.yandex.net/api/v1.5/tr.json/translate"
    key = "trnsl.1.1.20190404T201801Z.46480affa1f22724.45d5c8bd7677c228f167eb9fb0832897854ef4"
    lang = "en-ru"
    text = text
    r = requests.post(url, data={"key":key, "lang":lang, "text":text})
    return eval(r.text)["text"]

print(*get_transleat(text))

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex F, 2019-04-08
@vera_ira

#!/usr/bin/env python3.6
# -*- coding: utf-8 -*-
import warnings
import locale
import json
import requests
warnings.filterwarnings("ignore")
locale.setlocale(locale.LC_ALL, '')

yandexkey = "dict.1.1.there_are_a_lot_of_numbers"
lang = "ru-en"
text = "бред"
uri = f"https://dictionary.yandex.net/api/v1/dicservice.json/lookup?key={yandexkey}&lang={lang}&text={text}"
outelem = len(json.loads(requests.post(uri).text))
r = requests.post(uri)
for x in range(0, outelem + 1):
  print (eval(r.text)["def"][0]["tr"][x]["text"])

delirium
drivel
brad

D
Darkhan Kamaliev, 2017-01-31
@webirus

I can advise a stripped-down image of "Windows 7 on Eee PC" or XP. What drivers will get up and install, but it is possible from the manufacturer's website for old OS (operating systems). After installation (clean Windows), you can disable unnecessary services, windows defender, and so on. Should work more or less adequately.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question