Skip to content

Instantly share code, notes, and snippets.

@nicerobot
Forked from joneskoo/gist-backup.py
Last active April 15, 2022 23:13
Show Gist options
  • Save nicerobot/1622504 to your computer and use it in GitHub Desktop.
Save nicerobot/1622504 to your computer and use it in GitHub Desktop.
Clone or update a user's gists locally
#!/bin/bash
curl -ks https://gist.githubusercontent.com/nicerobot/1622504/raw/gist-backup.py | USER=${USER} python3
#!/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