imankulov / linguee-api

Proxy to convert HTML responses from linguee.com to JSON format
https://linguee-api.fly.dev/docs
MIT License
193 stars 39 forks source link

Basic set-up and usage #14

Closed jukhamil closed 3 years ago

jukhamil commented 3 years ago

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.

jukhamil commented 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.

imankulov commented 3 years ago

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']
imankulov commented 3 years ago

With this saying, if you decide to use Linguee API for something more than a playground, I would recommend launching your own Heroku instance.

Deploy

jukhamil commented 3 years ago

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

jukhamil commented 3 years ago

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

imankulov commented 3 years ago

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.

jukhamil commented 3 years ago

Awesome, thanks very much.