Last active
July 12, 2017 11:56
-
-
Save shahril96/d078d52965d586bff2ccd820dfaa305a to your computer and use it in GitHub Desktop.
Clone all gist from specified account (requires Requests)
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 | |
# -*- 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