-
-
Save nicerobot/1622504 to your computer and use it in GitHub Desktop.
Clone or update a user's gists locally
This file contains 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
#!/bin/bash | |
curl -ks https://gist.githubusercontent.com/nicerobot/1622504/raw/gist-backup.py | USER=${USER} python3 |
This file contains 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 python3 | |
# Clone or update all a user's gists | |
# curl -ks https://gist.githubusercontent.com/nicerobot/1622504/raw/backup.sh | bash | |
# curl -ks https://gist.githubusercontent.com/nicerobot/1622504/raw/backup.sh | USER=nicerobot bash | |
import json | |
from subprocess import call | |
from urllib.request import urlopen | |
import os | |
USER = os.environ['USER'] | |
with urlopen('https://api.github.com/users/'+USER+'/gists') as u: | |
startd = os.getcwd() | |
for gist in json.loads(u.read().decode('utf8')): | |
gistd = os.path.basename(gist['html_url']) | |
pull = gist['git_pull_url'] | |
print(pull) | |
if os.path.isdir(gistd): | |
os.chdir(gistd) | |
call(['git', 'pull', pull]) | |
os.chdir(startd) | |
else: | |
call(['git', 'clone', pull]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment