Closed jukhamil closed 3 years ago
Just to develop this -
I found the URL and was able to access the JSON using Python requests.get() and r.json() methods.
How should we parse the JSON returned? It's a complex, nested list of dictionaries.
What is the easiest way to extract the translations of a word from the JSON?
Thank you very much.
Hey @jukhamil,
The README provides instructions to install the server, not the client. In fact, there's no dedicated client, but as you pointed out, using requests
should be enough.
As for the concrete example.
What is the easiest way to extract the translations of a word from the JSON?
The simplest script can look like this.
import requests
url = "https://linguee-api-v2.herokuapp.com/api/v2/translations"
params = {"src": "pt", "dst": "en", "query": "bacalhau"}
resp = requests.get(url, params=params).json()
ret = []
for lemma in resp:
for translation in lemma['translations']:
ret.append(translation['text'])
print(ret)
It will print
['cod', 'codfish']
Got it, thanks very much. So instead of downloading scripts or something which parse the HTML response of Linguee's website, you put up a server which basically does that, and we access that server through HTML requests. What is the reason for designing the tool this way, instead of just writing methods which communicate with Linguee directly? I'm just purely curious so I can understand the tool better.
Thanks very much
By the way, are there restrictions on how heavily we can use it, i.e. the rate at which we could query the API?
Thanks very much
What is the reason for designing the tool this way, instead of just writing methods which communicate with Linguee directly?
HTTP provides a universal API that you can use from any programming language — besides, fewer problems with maintaining it on various platforms.
By the way, are there restrictions on how heavily we can use it, i.e. the rate at which we could query the API?
There are restrictions, but they are set by Linugee, not but the API server. Having a local copy installed makes your installation independent from other people who may use the same server simultaneously.
Awesome, thanks very much.
Hey,
I'm afraid I don't understand how to use the API. It says the installation instructions are on the GitHub, but I don't see them. In the docs, I see some example JSON statements, but I wouldn't know how to send that, maybe with python requests, to the Linguee API.
Could you please provide more basic usage instructions?
Do we need to download anything on our system, or do we just query the API by using a library like Python requests? But what is the basic URL structure for the API then, i.e. the main address before the query suffixes are added?
Thanks very much.