Skip to content

Instantly share code, notes, and snippets.

@lethalbit
Created January 27, 2016 03:41
Show Gist options
  • Save lethalbit/406209be53f793977583 to your computer and use it in GitHub Desktop.
Save lethalbit/406209be53f793977583 to your computer and use it in GitHub Desktop.
A quick and dirty repo cloner
#!/usr/bin/python3
import sys, os, json, urllib.request, subprocess
api_url = "https://api.github.com"
def garchive(username, org):
adir = "./garchive-"+username
if not os.path.exists(adir):
os.makedirs(adir)
os.chdir(adir)
req_rep = ""
if org:
req_rep = "orgs"
else:
req_rep = "users"
repos = json.loads(urllib.request.urlopen(api_url+"/"+ req_rep +"/"+username+"/repos").read().decode("utf-8"))
for repo in repos:
git_url = repo["html_url"]+".git"
subprocess.call(["git","clone",git_url])
if __name__ == "__main__":
if len(sys.argv) < 2:
print("usage: %s [-o] <username|org>" % (sys.argv[0]))
sys.exit(0)
else:
is_org = False
user = ""
if len(sys.argv) == 3:
if sys.argv[1] == "-o":
is_org = True
user = sys.argv[2]
else:
user = sys.argv[1]
garchive(user, is_org)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment