diff --git a/TODO.md b/TODO.md index 598d675..9358b94 100644 --- a/TODO.md +++ b/TODO.md @@ -2,3 +2,5 @@ 1. Add Travis 1. Add support for Python 2.7, 3.5, and 3.6 1. Organize docs and folder structure better +1. Add all scripts to single CLI for easy running, testing, and searching +1. Add License diff --git a/readme.md b/readme.md index 926be9d..59d5c64 100755 --- a/readme.md +++ b/readme.md @@ -32,3 +32,4 @@ 1. **30_fullcontact.py**: Call the [FullcContact](https://www.fullcontact.com/developer/) API 1. **31_youtube_sentiment.py**: Calculate sentiment score from the comments of a Youtube video 1. **32_stock_scraper.py**: Get stock prices +1. **34_git_all_repos.py**: Clone all repositories from a public user or organization on Github. Usage: `python git_all_repos.py users USER_NAME` or `python git_all_repos.py orgs ORG_NAME` diff --git a/scripts/34_git_all_repos.py b/scripts/34_git_all_repos.py new file mode 100644 index 0000000..b3e2d5b --- /dev/null +++ b/scripts/34_git_all_repos.py @@ -0,0 +1,42 @@ +import sys +import os +import requests + + +def get_total_repos(group, name): + repo_urls = [] + page = 1 + while True: + url = 'https://api.github.com/{0}/{1}/repos?per_page=100&page={2}' + r = requests.get(url.format(group, name, page)) + if r.status_code == 200: + rdata = r.json() + for repo in rdata: + repo_urls.append(repo['clone_url']) + if (len(rdata) >= 100): + page += 1 + else: + print('Found {0} repos.'.format(len(repo_urls))) + break + else: + print(r) + return False + return repo_urls + + +def clone_repos(all_repos): + count = 1 + print('Cloning...') + for repo in all_repos: + os.system('Git clone ' + repo) + print('Completed repo #{0} of {1}'.format(count, len(all_repos))) + count += 1 + +if __name__ == '__main__': + if len(sys.argv) > 2: + total = get_total_repos(sys.argv[1], sys.argv[2]) + if total: + clone_repos(total) + + else: + print('Usage: python USERS_OR_ORG GITHUB_USER_OR_ORG-NAME')