Skip to content

Commit 13426d1

Browse files
committed
--accept option for get, refs #50
1 parent 9eb5cce commit 13426d1

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

github_to_sqlite/cli.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -462,13 +462,20 @@ def emojis(db_path, auth, fetch):
462462
is_flag=True,
463463
help="Output newline-delimited JSON",
464464
)
465-
def get(url, auth, paginate, nl):
465+
@click.option(
466+
"--accept",
467+
help="Accept header to send, e.g. application/vnd.github.VERSION.html",
468+
)
469+
def get(url, auth, paginate, nl, accept):
466470
"Save repos owened by the specified (or authenticated) username or organization"
467471
token = load_token(auth)
468472
first = True
469473
should_output_closing_brace = not nl
470474
while url:
471-
response = utils.get(url, token)
475+
response = utils.get(url, token, accept=accept)
476+
if "html" in (response.headers.get("content-type") or ""):
477+
click.echo(response.text)
478+
return
472479
items = response.json()
473480
if isinstance(items, dict):
474481
if nl:

github_to_sqlite/utils.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,10 @@ def fetch_image(url):
651651
return requests.get(url).content
652652

653653

654-
def get(url, token=None):
654+
def get(url, token=None, accept=None):
655655
headers = make_headers(token)
656+
if accept:
657+
headers["accept"] = accept
656658
if url.startswith("/"):
657659
url = "https://api.github.com{}".format(url)
658660
response = requests.get(url, headers=headers)

0 commit comments

Comments
 (0)