Skip to content

Instantly share code, notes, and snippets.

@keepanote
Forked from nicerobot/backup.sh
Last active August 29, 2015 14:09
Show Gist options
  • Save keepanote/378bea36950b42fe73dd to your computer and use it in GitHub Desktop.
Save keepanote/378bea36950b42fe73dd to your computer and use it in GitHub Desktop.
#!/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 = os.environ['USER']
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