From 8f81297c65e65da2ba6eafd026268990f86f01b0 Mon Sep 17 00:00:00 2001 From: aaknitt Date: Thu, 25 Jan 2018 20:19:10 -0600 Subject: [PATCH 1/2] Update pushbullet.py Modified _get_data and _load_channels to accommodate getting multiple pages' worth of results back when retrieving the channel list. --- pushbullet/pushbullet.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/pushbullet/pushbullet.py b/pushbullet/pushbullet.py index 143d7ee..16f1549 100644 --- a/pushbullet/pushbullet.py +++ b/pushbullet/pushbullet.py @@ -60,8 +60,8 @@ def __init__(self, api_key, encryption_password=None, proxy=None): ) self._encryption_key = kdf.derive(encryption_password.encode("UTF-8")) - def _get_data(self, url): - resp = self._session.get(url) + def _get_data(self, url, prms=None): + resp = self._session.get(url,params=prms) if resp.status_code in (401, 403): raise InvalidKeyError() @@ -99,14 +99,20 @@ def _load_user_info(self): def _load_channels(self): self.channels = [] - + get_more_channels = True resp_dict = self._get_data(self.CHANNELS_URL) - 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) + 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 @staticmethod def _recipient(device=None, chat=None, email=None, channel=None): From f251e93366b535aff7cf8c273ed653b75d941653 Mon Sep 17 00:00:00 2001 From: aaknitt Date: Thu, 25 Jan 2018 20:56:59 -0600 Subject: [PATCH 2/2] Update pushbullet.py Removed print statement --- pushbullet/pushbullet.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pushbullet/pushbullet.py b/pushbullet/pushbullet.py index 16f1549..f0c26c7 100644 --- a/pushbullet/pushbullet.py +++ b/pushbullet/pushbullet.py @@ -102,7 +102,6 @@ def _load_channels(self): 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"):