Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
Charles
rvelov
Commits
38097365
Commit
38097365
authored
Nov 16, 2019
by
Charles
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve data saving to be more robust
parent
4aa19f61
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
3 deletions
+6
-3
velovpredict/scrape.R
velovpredict/scrape.R
+6
-3
No files found.
velovpredict/scrape.R
View file @
38097365
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"
),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment