Skip to content

Commit e44ebee

Browse files
committed
Simplified get() implementation, refs #50
1 parent b02bf13 commit e44ebee

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

github_to_sqlite/cli.py

+20-21
Original file line numberDiff line numberDiff line change
@@ -465,28 +465,27 @@ def emojis(db_path, auth, fetch):
465465
def get(url, auth, paginate, nl):
466466
"Save repos owened by the specified (or authenticated) username or organization"
467467
token = load_token(auth)
468-
if paginate or nl:
469-
first = True
470-
while url:
471-
response = utils.get(url, token)
472-
items = response.json()
473-
if first and not nl:
474-
click.echo("[")
475-
for item in items:
476-
if not first and not nl:
477-
click.echo(",")
478-
first = False
479-
if not nl:
480-
to_dump = json.dumps(item, indent=4)
481-
click.echo(textwrap.indent(to_dump, " "), nl=False)
482-
else:
483-
click.echo(json.dumps(item))
484-
url = response.links.get("next", {}).get("url")
485-
if not nl:
486-
click.echo("\n]")
487-
else:
468+
first = True
469+
while url:
488470
response = utils.get(url, token)
489-
click.echo(json.dumps(response.json(), indent=4))
471+
items = response.json()
472+
if first and not nl:
473+
click.echo("[")
474+
for item in items:
475+
if not first and not nl:
476+
click.echo(",")
477+
first = False
478+
if not nl:
479+
to_dump = json.dumps(item, indent=4)
480+
click.echo(textwrap.indent(to_dump, " "), nl=False)
481+
else:
482+
click.echo(json.dumps(item))
483+
if paginate:
484+
url = response.links.get("next", {}).get("url")
485+
else:
486+
url = None
487+
if not nl:
488+
click.echo("\n]")
490489

491490

492491
def load_token(auth):

0 commit comments

Comments
 (0)