Commit 38097365 authored by Charles's avatar Charles

improve data saving to be more robust

parent 4aa19f61
library(data.table)
library(RMySQL)
library(mailR)
......@@ -51,6 +51,10 @@ dispo_url <- paste0("https://download.data.grandlyon.com/ws/rdata/",
dt <- jsonlite::fromJSON(dispo_url)$values
dt <- data.table(dt)
filename <- file.path(Sys.getenv("VELOV_CSV"), "data",
paste0(as.integer(Sys.time()), ".csv"))
fwrite(dt, file = filename)
res <- tryCatch(dbWriteTable(con, "dispo", dt, append = TRUE),
error = function(e) FALSE,
warning = function(e) FALSE)
......@@ -78,13 +82,12 @@ if (res == FALSE) {
passwd = Sys.getenv("MAILJET_API_SECRET")),
authenticate = TRUE,
debug = FALSE)
fwrite(dt, file = file.path(Sys.getenv("VELOV_CSV"), "data",
paste0(as.integer(Sys.time()), ".csv")))
}
dbDisconnect(con)
if (res == TRUE) {
file.remove(filename)
dt <- data.table(time = Sys.time(),
success = TRUE)
fwrite(dt, file = file.path(Sys.getenv("VELOV_CSV"), "logs.csv"),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment