-
-
Save lyoshenka/de4d3a0e82d8be987d69 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Clone or update all a user's gists | |
# curl -ks https://gist.githubusercontent.com/lyoshenka/de4d3a0e82d8be987d69/raw/gist-backup.py | python | |
# curl -ks https://gist.githubusercontent.com/lyoshenka/de4d3a0e82d8be987d69/raw/gist-backup.py | USERNAME=lyoshenka python | |
# USERNAME=lyoshenka python gist-backup.py | |
import json | |
import urllib | |
from subprocess import call | |
from urllib import urlopen | |
import os | |
import math | |
USER = os.environ['USERNAME'] if 'USERNAME' in os.environ else 'lyoshenka' | |
perpage=30.0 | |
userurl = urlopen('https://api.github.com/users/' + USER) | |
public_gists = json.load(userurl) | |
gistcount = public_gists['public_gists'] | |
pages = int(math.ceil(float(gistcount)/perpage)) | |
for page in range(pages): | |
u = urlopen('https://api.github.com/users/' + USER + '/gists?page=' + str(page) + '&per_page=' + str(int(perpage))) | |
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