Skip to content

Instantly share code, notes, and snippets.

@asw456
Created June 9, 2013 05:28
Show Gist options
  • Save asw456/5737756 to your computer and use it in GitHub Desktop.
Save asw456/5737756 to your computer and use it in GitHub Desktop.
download Gists
#!/usr/bin/env python
# Clone or update all a user's gists
# curl -ks https://raw.github.com/gist/5466075/gist-backup.py | python
# curl -ks https://raw.github.com/gist/5466075/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