脚本将最新添加的图像下载到Dropbox目录中 [英] Script that downloads the most recently added image in a Dropbox directory

查看:107
本文介绍了脚本将最新添加的图像下载到Dropbox目录中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为自己的论文创建一个项目,但是我试图制作一个可以从Dropbox目录下载最受关注的图像的python脚本而感到困惑。我在下面显示的脚本可以下载特定的图像,但是,如何在/ photos目录中下载最新添加的图像?

I am creating a project for my thesis and I am stuck trying to make a python script that downloads the most resent image from a Dropbox directory. The script I show below can download specific images that I ask but, how can I download the most recently added image in the /photos directory?

import dropbox
dbx = dropbox.Dropbox("ACCESS_TOKEN")

with open("photo1.jpg", "wb") as f:
    metadata, res = dbx.files_download(path="/photos/photo1.jpg")
    f.write(res.content)


推荐答案

Dropbox API不提供直接列出方法特定路径中的最新文件,因此您需要使用 files_list_folder files_list_folder_continue 方法以列出所有文件夹的内容,然后对它们进行排序以找到所需的文件,例如,在这种情况下,该文件具有最新的 FileMetadata.server_modified 。。

The Dropbox API doesn't offer a direct way to list the most recent file(s) in a particular path, so you'll need to use the files_list_folder and files_list_folder_continue methods to list all of the contents of the folder, and then sort through them to find the desired file, i.e., in this case, the one with the latest FileMetadata.server_modified.

找到最新文件后,便可以使用其 id path_lower 属性,作为调用路径值dropbox.dropbox.Dropbox.files_download rel = nofollow noreferrer> files_download 来下载文件内容。

Once you find the most recent file, you can then use its id or path_lower property as the path value when calling files_download to download the file content.

这篇关于脚本将最新添加的图像下载到Dropbox目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆