-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from itsleeds/oweno-tfwm
Oweno tfwm v5
- Loading branch information
Showing
52 changed files
with
4,786 additions
and
1,159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
Package: UK2GTFS | ||
Type: Package | ||
Title: Converts UK transport timetable datasets to GTFS format | ||
Version: 0.2.1 | ||
Version: 0.3.0 | ||
Authors@R: c( | ||
person("Malcolm", "Morgan", email = "[email protected]", role = c("aut","cre"), | ||
comment = c(ORCID = "0000-0002-9488-9183")), | ||
person("Adrian", "Schönig", role = c("ctb")), | ||
person("Owen", "O'Neill", role = c("ctb")) | ||
person("Owen", "O'Neill", email = "[email protected]", role = c("aut"), | ||
comment = c(ORCID = "0009-0008-0595-3042")) | ||
) | ||
Maintainer: Malcolm Morgan <[email protected]> | ||
Description: The UK uses a range of odd formats to store timetable data, this package converts them to the nice GTFS format. | ||
|
@@ -21,7 +22,6 @@ LazyDataCompression: gzip | |
Imports: | ||
checkmate, | ||
calendar, | ||
collapse, | ||
data.table, | ||
dodgr, | ||
dplyr, | ||
|
@@ -31,12 +31,13 @@ Imports: | |
geodist, | ||
httr, | ||
iotools, | ||
stringr, | ||
sf, | ||
lubridate, | ||
purrr (>= 1.0), | ||
readr (>= 2.0), | ||
RcppSimdJson, | ||
stringr, | ||
stringi, | ||
sf, | ||
stats, | ||
tidyr, | ||
xml2, | ||
zip, | ||
|
@@ -47,4 +48,4 @@ Suggests: | |
rmarkdown, | ||
testthat | ||
VignetteBuilder: knitr | ||
RoxygenNote: 7.3.1 | ||
RoxygenNote: 7.3.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
nrdp_authenticate = function(username = Sys.getenv("NRDP_username"), | ||
password = Sys.getenv("NRDP_password")){ | ||
|
||
# Make the POST request | ||
form_data <- list( | ||
username = username, | ||
password = password | ||
) | ||
|
||
response <- httr::POST( | ||
url = 'https://opendata.nationalrail.co.uk/authenticate', | ||
body = form_data, | ||
encode = "form" | ||
) | ||
|
||
json = httr::content(response) | ||
|
||
return(json) | ||
|
||
|
||
} | ||
|
||
|
||
#' Download Timetable from National Rail Data Portal | ||
#' | ||
#' Downloads ATOC CIF timetables from https://opendata.nationalrail.co.uk | ||
#' @param destfile Detestation and name of the zip file | ||
#' @param username your username | ||
#' @param password your password | ||
#' @param url URL of data source | ||
#' @export | ||
|
||
nrdp_timetable = function(destfile = "timetable.zip", | ||
username = Sys.getenv("NRDP_username"), | ||
password = Sys.getenv("NRDP_password"), | ||
url = "https://opendata.nationalrail.co.uk/api/staticfeeds/3.0/timetable"){ | ||
|
||
|
||
|
||
token = nrdp_authenticate(username, password) | ||
|
||
response <- httr::GET( | ||
url = url, | ||
httr::add_headers(`X-Auth-Token` = token$token) | ||
) | ||
|
||
# Check if the request was successful | ||
if (httr::status_code(response) == 200) { | ||
# Write the content of the response to a file | ||
writeBin(httr::content(response, "raw"), destfile) | ||
cat("File downloaded successfully to", destfile) | ||
} else { | ||
cat("Failed to download the file. Status code:", httr::status_code(response)) | ||
} | ||
|
||
|
||
} | ||
|
||
#' Download Fares from National Rail Data Portal | ||
#' | ||
#' Downloads fares from https://opendata.nationalrail.co.uk | ||
#' @param destfile Detestation and name of the zip file | ||
#' @param username your username | ||
#' @param password your password | ||
#' @param url URL of data source | ||
#' @export | ||
#' | ||
nrdp_fares = function(destfile = "fares.zip", | ||
username = Sys.getenv("NRDP_username"), | ||
password = Sys.getenv("NRDP_password"), | ||
url = "https://opendata.nationalrail.co.uk/api/staticfeeds/2.0/fares"){ | ||
|
||
|
||
|
||
token = nrdp_authenticate(username, password) | ||
|
||
response <- httr::GET( | ||
url = url, | ||
httr::add_headers(`X-Auth-Token` = token$token) | ||
) | ||
|
||
# Check if the request was successful | ||
if (httr::status_code(response) == 200) { | ||
# Write the content of the response to a file | ||
writeBin(httr::content(response, "raw"), destfile) | ||
cat("File downloaded successfully to", destfile) | ||
} else { | ||
cat("Failed to download the file. Status code:", httr::status_code(response)) | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
#' Download routing from National Rail Data Portal | ||
#' | ||
#' Downloads routing from https://opendata.nationalrail.co.uk | ||
#' @param destfile Detestation and name of the zip file | ||
#' @param username your username | ||
#' @param password your password | ||
#' @param url URL of data source | ||
#' @export | ||
#' | ||
nrdp_routing = function(destfile = "routeing.zip", | ||
username = Sys.getenv("NRDP_username"), | ||
password = Sys.getenv("NRDP_password"), | ||
url = "https://opendata.nationalrail.co.uk/api/staticfeeds/2.0/routeing"){ | ||
|
||
|
||
|
||
token = nrdp_authenticate(username, password) | ||
|
||
response <- httr::GET( | ||
url = url, | ||
httr::add_headers(`X-Auth-Token` = token$token) | ||
) | ||
|
||
# Check if the request was successful | ||
if (httr::status_code(response) == 200) { | ||
# Write the content of the response to a file | ||
writeBin(httr::content(response, "raw"), destfile) | ||
cat("File downloaded successfully to", destfile) | ||
} else { | ||
cat("Failed to download the file. Status code:", httr::status_code(response)) | ||
} | ||
|
||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#' @keywords internal | ||
"_PACKAGE" | ||
|
||
## usethis namespace: start | ||
#' @import data.table | ||
#' @importFrom data.table ":=" | ||
## usethis namespace: end | ||
NULL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.