Skip to content

Instantly share code, notes, and snippets.

@AnthonyBloomer
Created June 12, 2017 20:30
Show Gist options
  • Save AnthonyBloomer/7ae867ff657bc3f2397ac53da8a75ba9 to your computer and use it in GitHub Desktop.
Save AnthonyBloomer/7ae867ff657bc3f2397ac53da8a75ba9 to your computer and use it in GitHub Desktop.
Backup public Github repos to a Dropbox account.
from github import Github
import dropbox
import os
import config
IGNORED_FILES = ['desktop.ini', 'thumbs.db', '.ds_store', 'icon\r', '.dropbox', '.dropbox.attr']
dc = dropbox.client.DropboxClient(config.dropbox_access_token)
g = Github(config.github_username, config.github_password)
def is_ignored(fn):
filename_lower = fn.lower()
for ignored_file in IGNORED_FILES:
if ignored_file in filename_lower:
return True
return False
if __name__ == '__main__':
try:
os.mkdir(config.github_username)
print 'Created directory...'
except OSError:
print 'Directory already exists. Continuing. '
pass
os.chdir(config.github_username)
for repo in g.get_user().get_repos():
if not repo.private:
os.system('git clone ' + repo.clone_url)
full_path = os.path.realpath(__file__)
rootdir = os.path.dirname(full_path)
print rootdir
for root, dirs, files in os.walk(rootdir):
for filename in files:
if is_ignored(filename):
continue
local_path = os.path.join(root, filename)
if '.git' in local_path:
continue
relative_path = os.path.relpath(local_path, rootdir)
dropbox_path = os.path.join(rootdir, relative_path)
with open(local_path, 'rb') as f:
print 'Uploading: ' + str(f)
dc.put_file(dropbox_path, f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment