Created
January 20, 2016 00:54
-
-
Save osteele/8b1dbe8d93ed7ba9179a to your computer and use it in GitHub Desktop.
Print a file's forks
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 | |
# INSTALL: pip install github3.py | |
# USAGE: ./get_file_forks.py AllenDowney/DataScience age_lm.py | |
# Set HOMEBREW_GITHUB_API_TOKEN to avoid Github's rate limit. | |
import os | |
import sys | |
import github3 | |
GITHUB_API_TOKEN = os.environ.get('HOMEBREW_GITHUB_API_TOKEN') | |
if GITHUB_API_TOKEN: | |
gh = github3.login(token=GITHUB_API_TOKEN) | |
else: | |
gh = github3 | |
def get_file_forks(user, repo, path): | |
repo = gh.repository(user, repo) | |
return ((fork.owner, content and content.decoded) for fork in repo.iter_forks() for content in [fork.contents(path)]) | |
if __name__ == '__main__': | |
if 1 < len(sys.argv) <= 3: | |
user, repo, path = '/'.join(sys.argv[1:]).split('/', 3) | |
else: | |
print >> sys.stderr, "USAGE: ./get_file_forks.py user repo path" | |
print >> sys.stderr, "USAGE: ./get_file_forks.py user/repo path" | |
print >> sys.stderr, "USAGE: ./get_file_forks.py user/repo/path" | |
sys.exit(-1) | |
for user, content in get_file_forks(user, repo, path): | |
if content: | |
print user.login, content[:60].replace('\n', '\\n') + '...' | |
else: | |
print user.login, 'n/a' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment