-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_gdrive_update.r
34 lines (21 loc) · 3.92 KB
/
test_gdrive_update.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# test google drive api
library(googledrive)
library(readr)
# get command line secret inputs
args <- commandArgs(trailingOnly = TRUE)
print(args)
# get the first input, which is the credential string
#credentials = "ewogICJ0eXBlIjogInNlcnZpY2VfYWNjb3VudCIsCiAgInByb2plY3RfaWQiOiAiZjEwMDBib3QiLAogICJwcml2YXRlX2tleV9pZCI6ICI5MThiMWRlYzBjODkxNzFiZDgwNTNkNTYzMGZmYmU4NGZkMTQ1NWYxIiwKICAicHJpdmF0ZV9rZXkiOiAiLS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tXG5NSUlFdkFJQkFEQU5CZ2txaGtpRzl3MEJBUUVGQUFTQ0JLWXdnZ1NpQWdFQUFvSUJBUUNsSDhnZVh2UytxMDdOXG5aRS9ZakxFbGxCdGNSYjVXYmpoQlhPYXdXQld4OGVicHo4VjlyVGZRUlV4UTEwaUZLSHNXV0dLREtMQXoxZzNCXG40NitXMEFGVk9HK3JtNVFNL0hFQVJDUlE3emRrLzZkVmtIbWFsMlhrT25RRWdPSCtpMis2dkhzdm0yRWJ0VlBjXG5FRzEyemxlOUpaY0N6N25zblMvTTBMOUxhcHh1YWl0M0ZML2NhaWpuUHpLS0w1UG5wVTdPQm1WT1E4N3JsVllxXG5NTmt5UWVZeTZiblJOMEJyaWJ3V0FIOE9Gcmp2QXE4YjRhQk40TnNZZ1lJaXhUYlhzODM0Vy9qRCtDUUR1SDRpXG5OZHVsK2RzekVtd0pVL2tPVnhISGkxR1ZrQm1KUHFYb2JaamNrNGo0Q2ZSNFo1UVpUVkgyNW5sWEJ0N3NPR0lMXG5NZURzUndXSkFnTUJBQUVDZ2dFQUFrRHAxRW56RHZaa2V6bGhoRE9Kc1FCQmdib1B4LzZyQStp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iAiaHR0cHM6Ly93d3cuZ29vZ2xlYXBpcy5jb20vcm9ib3QvdjEvbWV0YWRhdGEveDUwOS9mMTAwMGJvdC1zZXJ2aWNlLWFjY291bnQlNDBmMTAwMGJvdC5pYW0uZ3NlcnZpY2VhY2NvdW50LmNvbSIsCiAgInVuaXZlcnNlX2RvbWFpbiI6ICJnb29nbGVhcGlzLmNvbSIKfQo="
credentials <- args[[1]]
# second input: file path
#file_path <- "https://drive.google.com/file/d/1XVQnOnNg4SJxwaSq9PnUvKGzsl5wmp1o/view?usp=drive_link"
file_path <- args[[2]]
# authenticate
drive_auth(path = rawToChar(base64enc::base64decode(credentials)), email = "[email protected]" )
# read the file from google drive
state <- drive_read_string(file = file_path) %>% read_csv()
# update the last date by current date
state$lastDate <- Sys.time() %>% as.numeric()
# write the file back to google drive
state %>% write_csv("./temp.csv")
drive_update(file = file_path, media = "./temp.csv")