在R中自动执行Dropbox下载

时间:2021-03-28 07:37:33

I'm trying to set up an automation via R that will download a CSV file from Dropbox on a weekly basis. I'm using the retmis package.

我正在尝试通过R设置自动化,每周从Dropbox下载一个CSV文件。我正在使用retmis包。

The problem is, there is a part of the naming convention within the URL that changes each time someone uploads a new version of the file into the Dropbox folder.

问题是,URL中的一部分命名约定会在每次有人将新版本的文件上传到Dropbox文件夹时更改。

library(retmis)

    customer_id <- source_data("https://www.dropbox.com/s/yeeih34mueagpsx/customer_id_update_20180628_adv.csv?dl=1")

It's that middle part which throws a wrench into the automation process: yeeih34mueagpsx

这是中间部分,它引发了自动化过程:yeeih34mueagpsx

It's not going to be the same thing. The prior week it was:

这不会是一回事。前一周它是:

https://www.dropbox.com/s/tu5tp0ihplm7dh0/customer_id_update_20180621_adv.csv?dl=1

https://www.dropbox.com/s/tu5tp0ihplm7dh0/customer_id_update_20180621_adv.csv?dl=1

(You will notice it gets uploaded every Thursday)

(你会发现它每周四上传)

All I know is that it's going to be a 15 character string of letters and numbers.

我所知道的是它将是一个15个字符的字母和数字串。

Is this something can be automated, and if so, how can I go about doing it?

这件事是否可以自动化,如果是这样,我该如何去做呢?

1 个解决方案

#1


0  

These strings in the Dropbox shared links are random and not predictable. Every new shared link gets a new string.

Dropbox共享链接中的这些字符串是随机的,不可预测。每个新的共享链接都会获得一个新字符串

There are a few ways you might want to approach this:

您可能有几种方法可以解决此问题:

a) In your current set up, you include the date in the file name, so each week the upload results in a new file. If you only ever need the current week's data to be available though, and you have control over who or what is doing the uploading, you can instead omit the date from the filename and use the same file name/path every week by overwriting the data each time. If you do this, you can use the same shared link every week, and it will always just return the latest data.

a)在当前设置中,您将日期包含在文件名中,因此每周上传都会生成一个新文件。如果您只需要当前周的数据可用,并且您可以控制上传的对象或内容,您可以通过文件名省略日期并通过覆盖数据每周使用相同的文件名/路径每一次。如果您这样做,您可以每周使用相同的共享链接,它将始终只返回最新数据。

b) If you do need to keep each file though, you can use the Dropbox API to create a new shared link for each new file. To do so, you would use the /2/sharing/create_shared_link_with_settings endpoint. (I don't have sample R code for that, but there is a curl example you can translate, or use a third party library.)

b)如果确实需要保留每个文件,可以使用Dropbox API为每个新文件创建新的共享链接。为此,您将使用/ 2 / sharing / create_shared_link_with_settings端点。 (我没有示例R代码,但有一个卷曲示例,您可以翻译,或使用第三方库。)

c) If you can use the Dropbox API, and don't also need the shared link for something else, you can use the API to access the file data directly without creating a shared link. To do so, you would use the /2/files/download endpoint.

c)如果您可以使用Dropbox API,并且不需要共享链接用于其他内容,则可以使用API​​直接访问文件数据而无需创建共享链接。为此,您将使用/ 2 / files / download端点。

#1


0  

These strings in the Dropbox shared links are random and not predictable. Every new shared link gets a new string.

Dropbox共享链接中的这些字符串是随机的,不可预测。每个新的共享链接都会获得一个新字符串

There are a few ways you might want to approach this:

您可能有几种方法可以解决此问题:

a) In your current set up, you include the date in the file name, so each week the upload results in a new file. If you only ever need the current week's data to be available though, and you have control over who or what is doing the uploading, you can instead omit the date from the filename and use the same file name/path every week by overwriting the data each time. If you do this, you can use the same shared link every week, and it will always just return the latest data.

a)在当前设置中,您将日期包含在文件名中,因此每周上传都会生成一个新文件。如果您只需要当前周的数据可用,并且您可以控制上传的对象或内容,您可以通过文件名省略日期并通过覆盖数据每周使用相同的文件名/路径每一次。如果您这样做,您可以每周使用相同的共享链接,它将始终只返回最新数据。

b) If you do need to keep each file though, you can use the Dropbox API to create a new shared link for each new file. To do so, you would use the /2/sharing/create_shared_link_with_settings endpoint. (I don't have sample R code for that, but there is a curl example you can translate, or use a third party library.)

b)如果确实需要保留每个文件,可以使用Dropbox API为每个新文件创建新的共享链接。为此,您将使用/ 2 / sharing / create_shared_link_with_settings端点。 (我没有示例R代码,但有一个卷曲示例,您可以翻译,或使用第三方库。)

c) If you can use the Dropbox API, and don't also need the shared link for something else, you can use the API to access the file data directly without creating a shared link. To do so, you would use the /2/files/download endpoint.

c)如果您可以使用Dropbox API,并且不需要共享链接用于其他内容,则可以使用API​​直接访问文件数据而无需创建共享链接。为此,您将使用/ 2 / files / download端点。