demian-wolf / pyreverso

Reverso API wrapper for Python
https://reverso.net/
MIT License
49 stars 14 forks source link

Still working? #2

Closed harry-ezratty closed 3 years ago

harry-ezratty commented 3 years ago

Hi, does this still work?

I am not getting any results from the context search generator when searching for Japanese to English for search terms which return results when searching the reverso front end.

When I tried building a scraper myself for reverso (not using any API), they blocked my connections.

So I'm wondering if I'm just using it incorrectly or if they are now forbidding all scraping and thus this no longer works...

Thanks for you hard work.

demian-wolf commented 3 years ago

Hi,

I am not getting any results from the context search generator when searching for Japanese to English for search terms which return results when searching the reverso front end. ... So I'm wondering if I'm just using it incorrectly or if they are now forbidding all scraping and thus this no longer works.

I have just tried to reproduce your problem with こんにちは (=Hello), and everything worked fine. Here is an example that gets the first 5 examples and first 5 translations of this word:

from itertools import islice

from reverso_api.context import ReversoContextAPI

api = ReversoContextAPI(source_text="こんにちは",
                        source_lang="ja",
                        target_lang="en")

# First 5 examples:
for source_example, target_example in islice(api.get_examples(), 5):
    print(source_example.text, "<=>", target_example.text)

# First 5 translations:
for translation in islice(api.get_translations(), 5):
    print(translation.translation)

# Output:
こんにちは ピーターソンさん ミッシー・ブラマーです <=> Hello, Mr. Peterson, this is Missy Brammer.
世界のみなさん、こんにちはと。 <=> "Hello, people of the world!"
こんにちは、プラットフォーム・マーケッティングのPete Lavacheです。 <=> Hello, I am Pete Lavache from Platforms Marketing
こんにちは。Data Domain重複除外ストレージ・システムのトレーニング・ディスカッションへようこそ。 <=> Hello, and welcome to this training discussion on Data Domain Deduplication Storage systems.
バンコクからこんにちは! - HOKKAIDO Government Representative Office <=> Hello from Bangkok! - HOKKAIDO Government Representative Office
hello
computer
hola
good afternoon
everyone

It looks like you're using the API wrapper the wrong way. It would be better if you provide a minimal reproducible example of your code (a concise piece of code where the problem is seen).

By now I can make only a couple of assumptions about why do you get the problem: 1) Have you specified the right language code ("ja" for Japanese, not "jp", for example)? All language codes seem to correspond to the ISO 639-1. 2) Haven't you "exhausted" the generator before? For example, assigned api.get_examples() to a variable, converted its value to a list and tried to iterate over the (already exhausted) generator? Like this:

api = ReversoContextAPI(...)
examples = api.get_examples()
print(list(examples))  # you have exhausted the generator
for example in examples:  # generator is empty after ^^^
    print(example)

When I tried building a scraper myself for reverso (not using any API), they blocked my connections.

Don't worry about that. As far as I know, they block only single requests depending on the UserAgent (you haven't specified a fake one, right?). Once you specify a fake UserAgent, you will get access to the website from Python requests just as from a "real" web browser like Firefox. In this API wrapper, it is already done.

P.S.: tell me if it helped. We'll continue figuring it out if the problem persists. P.P.S.: glad to see you're interested in my project!

harry-ezratty commented 3 years ago

Hey! Sorry to take so long to get back to this, I just started a new job...

Man, thanks so much for such a detailed answer. If i had expected you to write so much, I def would've posted some code. I was just hoping you would confirm to me if still working or not so I could tell if i should spend any more time on it. Instead, you went ahead and fixed all my problems and explained to me how to deal with user agents. Class act.

Thanks!!! Working now, this great. I just wasted instantiating the generator correctly.

Reverso's example sentences are great, so I'm super happy to be able to use them in my code. Best regards, Harry

demian-wolf commented 3 years ago

Glad I was able to help you! :)