Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let the user choose how to handle rate limits #81

Open
catdevnull opened this issue Apr 8, 2024 · 3 comments
Open

Let the user choose how to handle rate limits #81

catdevnull opened this issue Apr 8, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@catdevnull
Copy link
Contributor

Hi! I've been liking this library a lot as you can see :)

Something that I would like to have for my project is being able to choose how rate limits are handled. Specifically, I want to implement a behavior similar to the one in twscrape where if an account has a rate limit, it re-tries with another account that doesn't. However, because of how twitter-scraper currently works it's not possible to choose, and it just waits until the rate limit is reset which can take a long time.

I'm probably going to do the easiest patch for my fork which is going to be throwing a special error (something like RateLimitError) from requestApi to be able to handle it from my code, but I would like to find a solution that can be applied upstream.

Thanks <3

catdevnull added a commit to catdevnull/twitter-scraper that referenced this issue Apr 8, 2024
this lets the user decide how to handle it

related: the-convocation#81
@karashiiro karashiiro added the enhancement New feature or request label Apr 9, 2024
@karashiiro
Copy link
Collaborator

Definitely open to this in general, though I'm a little less sure about how to actually go about it (still need to think it over).

I'm leaning towards making it part of the TwitterAuth interface and generalizing it a bit more, since that's already responsible for providing the fetch implementation, along with request/response transforms. From an implementation standpoint, it could just be a wrapper around the fetch implementation itself. On the other hand, there's not a clear way of communicating that this is where the functionality would live, so it could use a bit more of an API around it, maybe.

At any rate, the fetch provider API could actually work today for your use case, so that might be worth a try in the meantime 👀

@catdevnull
Copy link
Contributor Author

catdevnull commented Apr 17, 2024

Okay, I've implemented a PoC of account login as a request interceptor in this branch: https://github.com/catdevnull/milei-twitter/blob/scraper-resiliente-cuentas-interceptar/scraper-manzana/scraper.ts

It's a bit hacky and it doesn't actually switch accounts on errors right now, but it could be easily implemented (EDIT: now implemented :). I'll probably implement this in my staging environment soon.

It would probably be cleaner to use if we could access the cookie jar from outside the library

@karashiiro
Copy link
Collaborator

(ignore) referencing #84 for discoverability

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants