Skip to content

Instantly share code, notes, and snippets.

@evansde77
Created March 24, 2014 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evansde77/9749925 to your computer and use it in GitHub Desktop.
Save evansde77/9749925 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""
_gists_
functions for getting gists
Requires a section in your gitconfig like:
[cirrus]
github-user = evansde77
github-token = TOKENHERE
You probably need to pip install gitconfig as well
"""
import os
import gitconfig
import requests
def get_auth():
"""lookup auth from gitconfig"""
gitconfig_file = os.path.join(os.environ['HOME'], '.gitconfig')
config = gitconfig.config(gitconfig_file)
github_user = config.get('cirrus', 'github-user')
github_token = config.get('cirrus', 'github-token')
return github_user, github_token
def itergists(user, token):
"""yields each gist for the user"""
headers = {
'Content-Type':'application/json',
'Authorization': 'token %s' % token,
}
url = 'https://api.github.com/users/{user}/gists'.format(user=user)
resp = requests.get(url, headers=headers)
resp.raise_for_status()
data = resp.json()
for gist in data:
yield gist
if __name__ == '__main__':
for g in list_gists(*get_auth()):
print g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment