Created
March 24, 2014 21:48
-
-
Save evansde77/9749925 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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