当前位置: 首页>>代码示例>>Python>>正文


Python Dropbox.files_download_to_file方法代码示例

本文整理汇总了Python中dropbox.Dropbox.files_download_to_file方法的典型用法代码示例。如果您正苦于以下问题:Python Dropbox.files_download_to_file方法的具体用法?Python Dropbox.files_download_to_file怎么用?Python Dropbox.files_download_to_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dropbox.Dropbox的用法示例。


在下文中一共展示了Dropbox.files_download_to_file方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: DropboxHelper

# 需要导入模块: from dropbox import Dropbox [as 别名]
# 或者: from dropbox.Dropbox import files_download_to_file [as 别名]
class DropboxHelper(object):

    def __init__(self, access_token):
        self.dropbox = Dropbox(oauth2_access_token=access_token)

    def upload(self, filename, file_path):
        with open(file_path, 'rb') as f:
            try:
                self.dropbox.files_upload(f.read(), '/' + filename)
            except Exception:
                os.remove(file_path)
                raise CommandError('Unable to upload file to Dropbox. Maybe access token is invalid.')

    def delete_all_files(self):
        for i in self.dropbox.files_list_folder('').entries:
            self.dropbox.files_delete(i.path_lower)

    def download_last_backup(self, dir_path):
        entries = self.dropbox.files_list_folder('').entries

        if len(entries) == 0:
            raise CommandError('We could not find any backup.')

        entry = entries[-1]
        full_path = dir_path + entry.path_lower

        self.dropbox.files_download_to_file(full_path, entry.path_lower)
        return full_path, entry.content_hash
开发者ID:akoikelov,项目名称:djazz,代码行数:30,代码来源:cloud.py

示例2: download_dropboxfiles

# 需要导入模块: from dropbox import Dropbox [as 别名]
# 或者: from dropbox.Dropbox import files_download_to_file [as 别名]
def download_dropboxfiles(payload):
    # Get the Project
    project = Project.objects.get(pk=payload['project_id'])
    project.set_status('downloading')

    # Check to see what files to download from Dropbox
    client = Dropbox(project.user.dropboxinfo.access_token)
    num_files = 0
    for x in client.files_list_folder(project.path).entries:
        if x.path_lower.endswith('.jpg') and x.size > 0:
            # Download the file from Dropbox to local disk
            local_filename = os.path.split(x.path_lower)[-1]
            local_filepath = os.path.join(project.originals_path, local_filename)
            num_files += 1
            if os.path.exists(local_filepath): # and not payload.get('redownload') == True
                continue
            client.files_download_to_file(local_filepath, x.path_lower)

    
    # Get the metadata as a separate task
    new_task(project.user, {
        'action': 'extract_metadata',
        'project_id': project.pk
    })

    # schedule a thumbnail task
    new_task(project.user, {
        'action': 'makethumbnails',
        'project_id': project.pk
    })


    # Downloading files can take a long time
    # In the meantime this Project could have been changed by other tasks
    # Reload it before setting the status
    project = Project.objects.get(pk=payload['project_id'])
    project.num_files_on_dropbox = num_files
    project.status = 'layout'
    project.save()
    return {'downloaded_files_count':num_files}
开发者ID:epoz,项目名称:metabotnik,代码行数:42,代码来源:tasks.py


注:本文中的dropbox.Dropbox.files_download_to_file方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。