python ghclone.py
Follow the prompts
You should make sure you have ssh keys setup or you'll have to enter your username and password every time.
import getpass | |
import json | |
import os | |
from subprocess import call | |
import urllib2 | |
cred = { | |
'user': '', | |
'pass': '' | |
} | |
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm() | |
API_BASE_URL = "https://api.github.com" | |
def clone(): | |
password_mgr.add_password(None, API_BASE_URL, cred['user'], cred['pass']) | |
handler = urllib2.HTTPBasicAuthHandler(password_mgr) | |
opener = urllib2.build_opener(handler) | |
page = opener.open(API_BASE_URL + '/user/repos') | |
data = page.read() | |
page.close() | |
repos = json.loads(data) | |
os.chdir(target_dir) | |
cnt = 0 | |
for repo in repos: | |
url = repo['git_url'] | |
call(['git', 'clone', url]) | |
print("cloned %s" % url) | |
cnt += 1 | |
print('cloned %d repos in %s' % (cnt, target_dir)) | |
if __name__ == '__main__': | |
cred['user'] = raw_input('Username: ') | |
cred['pass'] = getpass.getpass('Password: ') | |
cwd = os.getcwd() | |
target_dir = os.path.abspath(os.path.expanduser( | |
raw_input('Target directory (%s): ' % cwd) or cwd)) | |
clone() |