Skip to content

Instantly share code, notes, and snippets.

@patperu
Created July 17, 2016 20:17
Show Gist options
  • Save patperu/dd4f3986f4a519d0dbd30f64289f65cd to your computer and use it in GitHub Desktop.
Save patperu/dd4f3986f4a519d0dbd30f64289f65cd to your computer and use it in GitHub Desktop.
Check route 101
library("rvest")
library("gtfsr")
library("dplyr")
library('tidyr')
amat_url <- "http://www.amat.pa.it/Le_Linee/linee_orario.php"
set_date <- function(x) {as.POSIXct(paste("2016/07/01", x, tz = "CET"))}
# BOM fixed
amat <- import_gtfs("amat_v08_fix.zip", local = TRUE)
# https://github.com/openamat/Official-Data/issues/11
t1 <- filter(amat$trips_df, route_id == "101", direction_id == 0 & service_id == "FR")
stop_t <- filter(amat$stop_times_df, trip_id %in% t1$trip_id) %>%
filter(stop_id == "1970") %>%
mutate(arrival_time = set_date(arrival_time),
departure_time = set_date(departure_time),
trip_id = as.numeric(trip_id)) %>%
#arrange(arrival_time) %>%
arrange(trip_id) %>%
filter(stop_sequence == 1)
head(stop_t)
tail(stop_t)
length((stop_t$trip_id))
#########################################################################
pgsession <- html_session(amat_url)
pgform <- html_form(pgsession)[[1]]
filled_form <- set_values(pgform, "voce" = "FR", name = "101")
res <- submit_form(pgsession, filled_form)
httr::content(res$response) %>%
html_nodes("body") %>%
html_nodes("table") %>% .[[4]] %>%
html_nodes("td") %>% html_text() %>%
gsub(",", ":", .) -> web_t
web_t <- paste0(web_t, ":00")
web_t <- data.frame(arrival_time = set_date(web_t),
id = "web_time",
stringsAsFactors = FALSE )
stop_t <- left_join(stop_t, web_t, by="arrival_time") %>%
arrange(arrival_time)
```R
## 431 x 11
trip_id arrival_time departure_time stop_id stop_sequence stop_headsign pickup_type drop_off_type shape_dist_traveled timepoint id
1 309 2016-07-01 05:15:00 2016-07-01 05:15:00 1970 1 <NA> 0 0 0 1 web_time
2 358 2016-07-01 05:20:00 2016-07-01 05:20:00 1970 1 <NA> 0 0 0 1 web_time
3 1070 2016-07-01 05:24:00 2016-07-01 05:24:00 1970 1 <NA> 0 0 0 1 <NA>
4 456 2016-07-01 05:30:00 2016-07-01 05:30:00 1970 1 <NA> 0 0 0 1 web_time
5 1141 2016-07-01 05:30:00 2016-07-01 05:30:00 1970 1 <NA> 0 0 0 1 web_time
6 530 2016-07-01 05:35:00 2016-07-01 05:35:00 1970 1 <NA> 0 0 0 1 web_time
7 1189 2016-07-01 05:36:00 2016-07-01 05:36:00 1970 1 <NA> 0 0 0 1 <NA>
8 1237 2016-07-01 05:42:00 2016-07-01 05:42:00 1970 1 <NA> 0 0 0 1 <NA>
9 187 2016-07-01 05:45:00 2016-07-01 05:45:00 1970 1 <NA> 0 0 0 1 web_time
10 1287 2016-07-01 05:48:00 2016-07-01 05:48:00 1970 1 <NA> 0 0 0 1 <NA>
11 212 2016-07-01 05:50:00 2016-07-01 05:50:00 1970 1 <NA> 0 0 0 1 web_time
12 1336 2016-07-01 05:54:00 2016-07-01 05:54:00 1970 1 <NA> 0 0 0 1 <NA>
13 238 2016-07-01 05:55:00 2016-07-01 05:55:00 1970 1 <NA> 0 0 0 1 web_time
14 928 2016-07-01 06:00:00 2016-07-01 06:00:00 1970 1 <NA> 0 0 0 1 <NA>
15 285 2016-07-01 06:05:00 2016-07-01 06:05:00 1970 1 <NA> 0 0 0 1 web_time
16 1000 2016-07-01 06:06:00 2016-07-01 06:06:00 1970 1 <NA> 0 0 0 1 <NA>
17 311 2016-07-01 06:10:00 2016-07-01 06:10:00 1970 1 <NA> 0 0 0 1 web_time
18 1072 2016-07-01 06:12:00 2016-07-01 06:12:00 1970 1 <NA> 0 0 0 1 <NA>
19 334 2016-07-01 06:15:00 2016-07-01 06:15:00 1970 1 <NA> 0 0 0 1 web_time
20 1143 2016-07-01 06:18:00 2016-07-01 06:18:00 1970 1 <NA> 0 0 0 1 <NA>
21 360 2016-07-01 06:20:00 2016-07-01 06:20:00 1970 1 <NA> 0 0 0 1 web_time
22 1191 2016-07-01 06:24:00 2016-07-01 06:24:00 1970 1 <NA> 0 0 0 1 <NA>
23 409 2016-07-01 06:25:00 2016-07-01 06:25:00 1970 1 <NA> 0 0 0 1 web_time
24 1239 2016-07-01 06:30:00 2016-07-01 06:30:00 1970 1 <NA> 0 0 0 1 <NA>
25 458 2016-07-01 06:35:00 2016-07-01 06:35:00 1970 1 <NA> 0 0 0 1 web_time
26 1289 2016-07-01 06:36:00 2016-07-01 06:36:00 1970 1 <NA> 0 0 0 1 <NA>
27 482 2016-07-01 06:40:00 2016-07-01 06:40:00 1970 1 <NA> 0 0 0 1 web_time
28 1338 2016-07-01 06:42:00 2016-07-01 06:42:00 1970 1 <NA> 0 0 0 1 <NA>
29 880 2016-07-01 06:48:00 2016-07-01 06:48:00 1970 1 <NA> 0 0 0 1 <NA>
30 532 2016-07-01 06:50:00 2016-07-01 06:50:00 1970 1 <NA> 0 0 0 1 web_time
.....
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment