Skip to content

kill request if there are no [more] available translation samples#3

Open
paulorssalves wants to merge 3 commits intoflagist0:masterfrom
paulorssalves:master
Open

kill request if there are no [more] available translation samples#3
paulorssalves wants to merge 3 commits intoflagist0:masterfrom
paulorssalves:master

Conversation

@paulorssalves
Copy link

Ой, братишка! Greetings from Brazil. Your API has been of great use to me. I'm using it to create material to study Russian on Anki. There was a little problem where if you made a request for translation samples for an entry that is not available on Reverso Context it would never stop doing the request, and then the server would inevitably throw a 429 exception (and if this kept happening your IP would be temporarily blocked from making requests, which is awful). Same thing would happen if you asked for a number of samples for a given word, but the number of available samples on Reverso Context for that word is smaller than the number you requested.

Anyway, my solution is not the most elegant but I think it solves the problem.

@flagist0
Copy link
Owner

Паоло, привет!)
Thank you for the pull request, I haven't bumped into this problem before. Also it's nice to hear that this package was of some value to you, thanks)
I think the good place for this change is in _translations_pager as it's responsible for iteration of results. You could stop the pager by just 'raise StopIteration()' to avoid changing the result type of get_translation_samples

@paulorssalves
Copy link
Author

Hello, Alexander! I have done what you suggested. I put a break statement in the _translations_pager instead of using StopIteration(), however. I tried doing it the way you proposed, but then it throws a runtime exception if StopIteration() is explicitly stated. The generator never actually gets to the end because it keeps returning empty lists (which the other function keeps scanning for content that is never found), so it seemed to me to be necessary to kill it from outside. The runtime exception could be handled, but I figured it would become too bulky to do it that way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants