Skip to content

Instantly share code, notes, and snippets.

@anpefi
Forked from iainmcampbell/gist-backup.py
Created February 7, 2016 18:51
Show Gist options
  • Save anpefi/81c1e5c380ed8f010b71 to your computer and use it in GitHub Desktop.
Save anpefi/81c1e5c380ed8f010b71 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 = 'anpefi'
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