Commit 69cc16ac authored by Charles's avatar Charles

add scraping script

parent b7e58189
library(data.table)
library(RMySQL)
con <- dbConnect(MySQL(),
user = Sys.getenv("VELOV_USER"),
password = Sys.getenv("VELOV_PASSWORD"),
dbname = Sys.getenv("VELOV_DB"),
host = Sys.getenv("VELOV_HOST"),
port = as.numeric(Sys.getenv("VELOV_PORT")))
if (!"dispo" %in% dbListTables(con)) {
# Create disponibilite table
df <- data.frame(
number = integer(),
pole = character(),
available_bikes = integer(),
code_insee = character(),
lng = numeric(),
availability = character(),
availabilitycode = integer(),
etat = character(),
startdate = character(),
langue = character(),
bike_stands = integer(),
last_update = character(),
available_bike_stands = integer(),
gid = integer(),
titre = character(),
status = character(),
commune = character(),
description = character(),
nature = character(),
bonus = character(),
address2 = character(),
address = character(),
lat = numeric(),
last_update_fme = character(),
enddate = character(),
name = character(),
banking = logical(),
nmarrond = integer()
)
dbWriteTable(con, "dispo", df, overwrite = TRUE)
}
dispo_url <- paste0("https://download.data.grandlyon.com/ws/rdata/",
"jcd_jcdecaux.jcdvelov/all.json")
dt <- jsonlite::fromJSON(dispo_url)$values
dt <- data.table(dt)
dbWriteTable(con, "dispo", dt, append = TRUE)
dbDisconnect(con)
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