Skip to content

Instantly share code, notes, and snippets.

@Inndy
Last active July 9, 2021 19:06
Show Gist options
  • Save Inndy/6771619dcd037f6570e8d77deec2601d to your computer and use it in GitHub Desktop.
Save Inndy/6771619dcd037f6570e8d77deec2601d to your computer and use it in GitHub Desktop.
# -*- 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)
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment