Skip to content

Commit

Permalink
Merge pull request #1 from trailbehind/fix/paginator
Browse files Browse the repository at this point in the history
Revise Pagination
  • Loading branch information
acannistra authored Oct 15, 2020
2 parents 276a055 + 1a3d10c commit 003bbb7
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions satsearch/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def found(self, headers=None):
}
kwargs.update(self.kwargs)
url = urljoin(self.url, 'search')

results = self.query(url=url, headers=headers, **kwargs)
# TODO - check for status_code
logger.debug(f"Found: {json.dumps(results)}")
Expand Down Expand Up @@ -92,6 +92,7 @@ def items(self, limit=10000, page_limit=500, headers=None):
if found > limit:
logger.warning('There are more items found (%s) than the limit (%s) provided.' % (found, limit))

page = 1
nextlink = {
'method': 'POST',
'href': urljoin(self.url, 'search'),
Expand All @@ -108,14 +109,17 @@ def items(self, limit=10000, page_limit=500, headers=None):
_headers = nextlink.get('headers', {})
_body = nextlink.get('body', {})
_body.update({'limit': page_limit})

if nextlink.get('merge', False):
_headers.update(headers)
_body.update(self.kwargs)
resp = self.query(url=nextlink['href'], headers=_headers, **_body)
items += [Item(i) for i in resp['features']]
links = [l for l in resp['links'] if l['rel'] == 'next']
nextlink = links[0] if len(links) == 1 else None
if len(resp['features']) == 0:
break
else:
items += [Item(i) for i in resp['features']]
page = page + 1
nextlink['body']['page'] = page

# retrieve collections
collections = []
Expand Down

0 comments on commit 003bbb7

Please sign in to comment.