Skip to content

Instantly share code, notes, and snippets.

@osteele
Created January 20, 2016 00:54
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 osteele/8b1dbe8d93ed7ba9179a to your computer and use it in GitHub Desktop.
Save osteele/8b1dbe8d93ed7ba9179a to your computer and use it in GitHub Desktop.
Print a file's forks
#!/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