Skip to content

Instantly share code, notes, and snippets.

@ishitcno1
Created June 23, 2014 23:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ishitcno1/228e1b6180e0981eadb1 to your computer and use it in GitHub Desktop.
Save ishitcno1/228e1b6180e0981eadb1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# Clone or update all a user's gists
# curl -ks https://gist.githubusercontent.com/fedir/5466075/raw/gist-backup.py | USER=fedir python
# USER=fedir python gist-backup.py
import json
import urllib
from subprocess import call
from urllib import urlopen
import os
USER = os.environ['USER']
u = urlopen('https://api.github.com/users/' + USER + '/gists')
gists = json.load(u)
startd = os.getcwd()
for gist in gists:
gistd = gist['id']
if os.path.isdir(gistd):
os.chdir(gistd)
call(['git', 'pull', 'git://gist.github.com/' + gistd + '.git'])
os.chdir(startd)
else:
call(['git', 'clone', 'git://gist.github.com/' + gistd + '.git'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment