Last active
July 9, 2021 19:06
-
-
Save Inndy/6771619dcd037f6570e8d77deec2601d to your computer and use it in GitHub Desktop.
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
# -*- coding: utf-8 -*- | |
"""DropboxToGDrive.ipynb | |
Automatically generated by Colaboratory. | |
""" | |
from google.colab import drive | |
drive.mount('/content/drive') | |
!mkdir -p /content/drive/MyDrive/TARGET_DIR | |
!ls -l /content/drive/MyDrive/TARGET_DIR | |
!pip install dropbox | |
import dropbox | |
import os | |
dbx = dropbox.Dropbox('ACCESS_TOKEN_HERE') | |
dropbox_folder = '/data' | |
def transfer_files(metadata): | |
for entry in metadata.entries: | |
dbx_path = '%s/%s' % (dropbox_folder, entry.name) | |
local_path = '/content/drive/MyDrive/TARGET_DIR/' + entry.name | |
if os.path.exists(local_path): | |
continue | |
print(dbx_path, end=' ... ') | |
meta, resp = dbx.files_download(dbx_path) | |
print('done!') | |
with open(local_path, 'wb') as fp: | |
fp.write(resp.content) | |
metadata = dbx.files_list_folder(dropbox_folder) | |
transfer_files(metadata) | |
while metadata.has_more: | |
print('has more!') | |
metadata = dbx.files_list_folder_continue(metadata.cursor) | |
transfer_files(metadata) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment