Skip to content

Instantly share code, notes, and snippets.

@srhopkins
Created October 12, 2022 02:43
Show Gist options
  • Save srhopkins/952a424264caf1cc859102642bd5923c to your computer and use it in GitHub Desktop.
Save srhopkins/952a424264caf1cc859102642bd5923c to your computer and use it in GitHub Desktop.
import requests
token = ''
def github_request(uri, method='get', **kwargs):
'''GitHub API wrapper for auth and baseline vars'''
if not uri.startswith('http'):
uri = f'https://api.github.com/{uri}'
return requests.request(method, uri, headers={
'Authorization': 'token ' + token
}, **kwargs)
def github_paginator(uri, **kwargs):
resp = github_request(uri, **kwargs)
yield resp
while True:
try:
resp = next(github_paginator(resp.links['next']['url'], **kwargs))
yield resp
except KeyError:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment