library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
## ✔ ggplot2 3.2.1 ✔ purrr 0.3.3
## ✔ tibble 2.1.3 ✔ dplyr 0.8.4
## ✔ tidyr 1.0.2 ✔ stringr 1.4.0
## ✔ readr 1.3.1 ✔ forcats 0.4.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(odbc)
library(bikeHelpR)
con <- dbConnect(odbc::odbc(), "Content DB", timeout = 10)
Download updated data
feeds <- feeds_urls()
# Get station status Data
dat <- feeds %>%
filter(name == "station_status") %>%
pull(url) %>%
get_data()
(df <- dat %>%
magrittr::extract2("data") %>%
mutate(time = dat$last_updated) %>%
select(is_installed, num_bikes_available, last_reported,
is_renting, eightd_has_available_keys, num_docks_available,
num_docks_disabled, is_returning, station_id,
num_ebikes_available, num_bikes_disabled, time))
## # A tibble: 778 x 12
## is_installed num_bikes_avail… last_reported is_renting eightd_has_avai…
## <int> <int> <int> <int> <lgl>
## 1 1 0 1713377772 1 FALSE
## 2 1 12 1713377772 1 FALSE
## 3 1 0 1713377774 1 FALSE
## 4 1 2 1713377773 1 FALSE
## 5 1 5 1713377805 1 FALSE
## 6 1 6 1713377811 1 FALSE
## 7 1 11 1713377811 1 FALSE
## 8 1 10 1713377811 1 FALSE
## 9 1 1 1713377811 1 FALSE
## 10 1 3 1713377810 1 FALSE
## # … with 768 more rows, and 7 more variables: num_docks_available <int>,
## # num_docks_disabled <int>, is_returning <int>, station_id <chr>,
## # num_ebikes_available <int>, num_bikes_disabled <int>, time <dttm>
dbWriteTable(con, "bike_raw_data", df, append = TRUE)
dbDisconnect(con)