Skip to content

Instantly share code, notes, and snippets.

@shahril96
Last active July 12, 2017 11:56
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 shahril96/d078d52965d586bff2ccd820dfaa305a to your computer and use it in GitHub Desktop.
Save shahril96/d078d52965d586bff2ccd820dfaa305a to your computer and use it in GitHub Desktop.
Clone all gist from specified account (requires Requests)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Clone all gists of GitHub username given on the command line."""
import subprocess
import sys
import requests
if len(sys.argv) > 1:
gh_user = sys.argv[1]
else:
print("Usage: gist-clone-all.py <GitHub username>")
sys.exit(1)
i = 1
while True:
data = requests.get('https://api.github.com/users/{}/gists?page={}'.format(gh_user, i)).json()
# break if API returns no data
if not data:
break
for gist in data:
ret = subprocess.call(['git', 'clone', gist['git_pull_url']])
if ret != 0:
print("ERROR cloning gist %s. Please check output." % gist['id'])
i += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment