-
-
Notifications
You must be signed in to change notification settings - Fork 4
added paginator to spotify client #506
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
base: main
Are you sure you want to change the base?
Conversation
Hi @joostlek, just wanted to point out I made a PR for spotifyaio and also provide some details regarding the change. Currently, this PR is purely foundation implementation for requirements that Spotcast has. We need to be able to pull an arbitrary number of items from the API that sometimes require more than the limit per single call. The The method can be called with the parameter This is refactored version of the _paginator Spotcast currently uses, but I do think it would be worth while for the underlying library to manage this part instead. My goal after would be to refactor the different methods that have a If you have any questions on my change, please ask. Also, if there are any changes you would like to better fit in the structure and style of the library, please provide your comments. |
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. Thank you for your contributions. |
Would it maybe make sense to have a value return an async generator? This way we can just do async for track in await client.get_tracks()
pass The twitch API does that and it makes the library really nice to work with, wdyt? |
@joostlek, I like the idea, do you have a link for where its being used? I'll look into making the change. I could replace the page reader into a generic function that handles the generator and then we would move the logic of stopping the read at the functions levels based on the max items requested. I'll review my current PR next week and get back to you. |
@joostlek, was that what you had in mind? Modified the async def get_tracks(self, max_items) -> Generator[dict, None, None]:
async for chunk in self._paginator("endpoint", max_items=max_items):
for track in chunk:
yield track Please tell me if you had something else in mind or would want deeper changes |
I have this implemented with aioyoutube, https://github.com/joostlek/python-youtube/blob/main/src/youtubeaio/youtube.py#L194-L212 for example. You can use a helper like I got this from twitchAPI and I kinda like the way as it is easier for the implementer to actually use and don't care about how pages work. WDYT? |
@joostlek. I like the idea and I'm all in to align on other projects. I'll try to make the modification during the weekend and get back to you on that. Thank you for the reference, that makes it much clearer |
I'll try to get to it quicker this time 👍🏻 |
Proposed Changes
This functionality is required for Spotcast to be able to move to
spotifyaio
pytest has been validated to provide full coverage with current process.