Clone or update all gists from a specified user
#!/usr/bin/env python
import sys
import requests
from os.path import exists, join
from subprocess import CalledProcessError, check_call
if len(sys.argv) > 1:
github_user = sys.argv[1]
else:
sys.exit("Usage: python clone_gists.py <username>")
all_gists = requests.get('https://api.github.com/users/%s/gists' % github_user)
for gist in all_gists.json():
try:
gist_desc = gist['description']
if not exists(join(gist_desc, '.git')):
check_call(['git', 'clone', gist['git_pull_url'], gist_desc])
else:
check_call(['git', '-C', gist_desc, 'pull', '-v'])
except CalledProcessError:
print("ERROR cloning/updating gist %s (%s)" % gist['id'], gist_desc)
except KeyboardInterrupt:
break