Created
October 13, 2016 01:19
-
-
Save dotnwat/1ca1b8529ad6b2a8c02c1b7cc112cb7a 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 | |
import sys | |
import time | |
import requests | |
def _get_forks(url): | |
req = requests.get(url) | |
json = req.json() | |
next_url = req.links.get('next', None) | |
if next_url: next_url = next_url['url'] | |
return [e['git_url'] for e in json], next_url | |
def get_forks(user, repo): | |
fork_list = [] | |
url = "https://api.github.com/repos/%s/%s/forks" % (user, repo) | |
while url is not None: | |
time.sleep(2) # try to keep github throttle happy | |
forks, url = _get_forks(url) | |
fork_list = fork_list + forks | |
return fork_list | |
if __name__ == "__main__": | |
if len(sys.argv) != 3: | |
print "usage: %s <user> <repo>" % (sys.argv[0],) | |
sys.exit(1) | |
fork_urls = get_forks(sys.argv[1], sys.argv[2]) | |
for url in fork_urls: | |
print url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment