-
-
Save HorlogeSkynet/968eaa45ec02744375b6126f31d83008 to your computer and use it in GitHub Desktop.
GitHub's Gists Backup
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 python3 | |
import os | |
import json | |
import subprocess | |
import urllib.request | |
# Just edit this with your GitHub's username | |
USERNAME = 'HorlogeSkynet' | |
# Your gists will be into a folder named '`USERNAME`_Gists' | |
PATH = USERNAME + '_Gists' | |
# Checks existence (or creates) a directory which will contain the backup gists | |
if not os.path.exists(PATH): | |
os.makedirs(PATH) | |
# Move into it ! | |
os.chdir(PATH) | |
# Clone each gists of your account | |
for gist in json.loads(urllib.request.urlopen("https://api.github.com/users/" + USERNAME + "/gists").read().decode()): | |
# If the project does not exist on the filesystem yet... | |
if not os.path.exists(gist['id']): | |
# ... let's clone it | |
subprocess.call(['git', 'clone', gist['git_pull_url']]) | |
# It DOES exist... | |
else: | |
# Move into the directory and pull it from the remote repository | |
os.chdir(gist['id']) | |
subprocess.call(['git', 'pull', 'origin', 'master']) | |
# Don't forget to go back to the root saves's directory | |
os.chdir('..') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment