Created
July 9, 2014 09:21
-
-
Save mperlet/102381f0d9d66fe54bfb to your computer and use it in GitHub Desktop.
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
from dropbox import client, rest, session | |
import os,sys | |
#Const | |
APP_KEY = '' | |
APP_SECRET = '' | |
ACC_KEY = '' | |
ACC_SECRET = '' | |
ACCESS_TYPE = 'dropbox' | |
folder_to_sync = '/' | |
count_fails = 0 | |
#DropBox-Api | |
sess = session.DropboxSession(APP_KEY, APP_SECRET, ACCESS_TYPE) | |
sess.set_token(ACC_KEY, ACC_SECRET) | |
client = client.DropboxClient(sess) | |
# Func to Sync | |
def sync_it(folder): | |
counter_new = 0 | |
counter_file = 0 | |
if not os.path.exists(".%s" % folder): | |
os.makedirs(".%s" % folder) | |
subfolders = client.metadata(folder)['contents'] | |
for fol in subfolders: | |
file_or_folder = fol['path'] | |
if not fol['is_dir']: | |
counter_file += 1 | |
if not os.path.exists(".%s" % file_or_folder): | |
f, metadata = client.get_file_and_metadata(file_or_folder) | |
out = open(".%s" % file_or_folder, 'wb') | |
out.write(f.read()) | |
out.close() | |
sys.stdout.write("\rOK -%s" % file_or_folder + ' ' * 15) | |
sys.stdout.flush() | |
counter_new += 1 | |
else: | |
sys.stdout.write("\rVRH-%s" % file_or_folder + ' ' * 15) | |
sys.stdout.flush() | |
else: | |
sync_it(file_or_folder) | |
return [counter_file, counter_new] | |
# Run | |
while(count_fails<10): | |
try: | |
sync_it(folder_to_sync) | |
except: | |
count_fails += 1 | |
print "\rFAIL: %d" % count_fails |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment