Skip to content

Commit

Permalink
Simplified get() implementation, refs #50
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Sep 17, 2020
1 parent b02bf13 commit e44ebee
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions github_to_sqlite/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,28 +465,27 @@ def emojis(db_path, auth, fetch):
def get(url, auth, paginate, nl):
"Save repos owened by the specified (or authenticated) username or organization"
token = load_token(auth)
if paginate or nl:
first = True
while url:
response = utils.get(url, token)
items = response.json()
if first and not nl:
click.echo("[")
for item in items:
if not first and not nl:
click.echo(",")
first = False
if not nl:
to_dump = json.dumps(item, indent=4)
click.echo(textwrap.indent(to_dump, " "), nl=False)
else:
click.echo(json.dumps(item))
url = response.links.get("next", {}).get("url")
if not nl:
click.echo("\n]")
else:
first = True
while url:
response = utils.get(url, token)
click.echo(json.dumps(response.json(), indent=4))
items = response.json()
if first and not nl:
click.echo("[")
for item in items:
if not first and not nl:
click.echo(",")
first = False
if not nl:
to_dump = json.dumps(item, indent=4)
click.echo(textwrap.indent(to_dump, " "), nl=False)
else:
click.echo(json.dumps(item))
if paginate:
url = response.links.get("next", {}).get("url")
else:
url = None
if not nl:
click.echo("\n]")


def load_token(auth):
Expand Down

0 comments on commit e44ebee

Please sign in to comment.