Skip to content
This repository has been archived by the owner on Jul 7, 2022. It is now read-only.

get_channel method doesn't support multiple pages of results #127

Open
aaknitt opened this issue Jan 22, 2018 · 4 comments
Open

get_channel method doesn't support multiple pages of results #127

aaknitt opened this issue Jan 22, 2018 · 4 comments

Comments

@aaknitt
Copy link

aaknitt commented Jan 22, 2018

The get_channel method loads channels for the current user and then returns an error "No channel found with channel_tag" when the channel is not found. However it doesn't handle multiple pages of results which means this will break if you have more than 20 channels.

The code does have some methods that handle multiple pages of results, but it looks like it only is used for getting pushes, not channels.

@aaknitt
Copy link
Author

aaknitt commented Jan 22, 2018

Corrected this issue by modifying

get_data as follows:

    def _get_data(self, url, prms=None):
        resp = self._session.get(url,params=prms)

        if resp.status_code in (401, 403):
            raise InvalidKeyError()
        elif resp.status_code == 429:
            raise PushbulletError("Too Many Requests, you have been ratelimited")
        elif resp.status_code != requests.codes.ok:
            raise PushbulletError(resp.status_code)

and _load_channels as follows:

def _load_channels(self):
        self.channels = []
        get_more_channels = True
        resp_dict = self._get_data(self.CHANNELS_URL)
        while get_more_channels == True:
            print resp_dict
            channel_list = resp_dict.get("channels", [])
            for channel_info in channel_list:
                if channel_info.get("active"):
                    c = Channel(self, channel_info)
                    self.channels.append(c)
            if "cursor" in resp_dict:
                cursor = resp_dict.get("cursor")
                resp_dict = self._get_data(self.CHANNELS_URL,prms={'cursor' : cursor})
            else:
                get_more_channels = False

I'll see if I can figure out how to use git to submit a fix.

@aaknitt
Copy link
Author

aaknitt commented Jan 26, 2018

Completed pull request
#128

@kovacsbalu
Copy link
Collaborator

Can you please add some test for this functionality?

@rbrcsk
Copy link
Collaborator

rbrcsk commented Oct 20, 2020

Hey @aaknitt I'll merge your PR, (or something similar) and do a release this week.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants