Skip to content

Instantly share code, notes, and snippets.

@iainmcampbell
Forked from joneskoo/gist-backup.py
Last active February 7, 2016 18:51
Show Gist options
  • Save iainmcampbell/a7790f42725ffd7029fd to your computer and use it in GitHub Desktop.
Save iainmcampbell/a7790f42725ffd7029fd to your computer and use it in GitHub Desktop.
gist backup
#!/usr/bin/env python
# Git clone all my gists
import json
import urllib
from urllib import urlopen
from subprocess import call
import os
USER = 'iainmcampbell'
BASE_PATH = os.getcwd()
u = urlopen('https://api.github.com/users/'+USER+'/gists')
gists = json.load(u)
for gist in gists:
gist_path = BASE_PATH + '/' + gist['id']
if os.path.exists(gist_path):
print( '\n' + gist['id'] + ' exists, pulling')
os.chdir(gist_path)
call(['git', 'pull', 'origin', 'master'])
else:
print( '\n' + gist['id'] + ' is new, cloning')
os.chdir(BASE_PATH)
call(['git', 'clone', 'git://gist.github.com/' + gist['id'] + '.git'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment