Skip to content

Instantly share code, notes, and snippets.

@endolith
Forked from nicerobot/backup.sh
Created May 18, 2012 15:49
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 endolith/2725965 to your computer and use it in GitHub Desktop.
Save endolith/2725965 to your computer and use it in GitHub Desktop.
Clone or update a user's gists locally
#!/usr/bin/env python
# Clone or update all a user's gists
# curl -ks https://raw.github.com/gist/1622504/gist-backup.py | python
# curl -ks https://raw.github.com/gist/1622504/gist-backup.py | USER=nicerobot python
import json
import urllib
from subprocess import call
from urllib import urlopen
import os
USER = 'endolith'
u = urlopen('https://gist.github.com/api/v1/json/gists/' + USER)
gists = json.load(u)['gists']
startd = os.getcwd()
for gist in gists:
gistd = gist['repo']
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