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

Handle multiple pages of returned results when getting channels #128

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions pushbullet/pushbullet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -99,14 +99,19 @@ 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:
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):
Expand Down