Skip to content
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

Deal with pagination in list-sources #137

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
20 changes: 14 additions & 6 deletions mapbox_tilesets/scripts/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import click
import cligj
import base64
import re
from requests_toolbelt import MultipartEncoder, MultipartEncoderMonitor

import mapbox_tilesets
Expand Down Expand Up @@ -708,12 +709,19 @@ def list_sources(username, token=None):
url = "{0}/tilesets/v1/sources/{1}?access_token={2}".format(
mapbox_api, username, mapbox_token
)
r = s.get(url)
if r.status_code == 200:
for source in r.json():
click.echo(source["id"])
else:
raise errors.TilesetsError(r.text)
pattern = re.compile("<(http[^>]*)>")
while url is not None:
r = s.get(url)
url = None
if 'Link' in r.headers:
matched = pattern.match(r.headers['Link'])
if matched:
url = matched[1] + "&access_token=" + mapbox_token
if r.status_code == 200:
for source in r.json():
click.echo(source["id"])
else:
raise errors.TilesetsError(r.text)


def validate_stream(features):
Expand Down