Skip to content

Commit

Permalink
update ULEZ.r
Browse files Browse the repository at this point in the history
  • Loading branch information
wengraf committed Mar 22, 2021
1 parent e21381a commit ca0645b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
18 changes: 9 additions & 9 deletions R/ulez.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#' Download DVLA-based vehicle data from the TfL API using VRM.
#'
#' @section Details:
#' This function takes a a character vector of vehicle registrations (VRMs) and returns DVLA-based vehicle data from TfL's API, included ULEZ eligibility.
#' This function takes a character vector of vehicle registrations (VRMs) and returns DVLA-based vehicle data from TfL's API, included ULEZ eligibility.
#' It returns a data frame of those VRMs which were successfully used with the TfL API. Vehicles are either compliant, non-compliant or exempt. ULEZ-exempt vehicles will not have all vehicle details returned - they will simply be marked "exempt".
#'
#' Be aware that the API has usage limits. The function will therefore limit API calls to 50 per minute.
#' Be aware that the API has usage limits. The function will therefore limit API calls to below 50 per minute - this is the maximum rate before an API key is required.
#'
#' @param vrm A list of VRMs as character strings.
#'
Expand Down Expand Up @@ -41,24 +41,24 @@ get_ULEZ = function(vrm) {
starttime = Sys.time()
URL = as.character(paste('https://api.tfl.gov.uk/Vehicle/UlezCompliance?vrm=',vrm[i],sep=""))
d = curl::curl_fetch_memory(URL)
apistatus <- d$status_code
apistatus = d$status_code
if(apistatus != 200L){
result <- as.data.frame(t(c(vrm[i],apistatus)))
result = as.data.frame(t(c(vrm[i],apistatus)))
colnames(result) = c("vrm", "API Status")
result.list[[i]] <- result
result.list[[i]] = result
rm(result, d)
next()}
endtime <- Sys.time()
calltime <- as.numeric(endtime) - as.numeric(starttime)
endtime = Sys.time()
calltime = as.numeric(endtime) - as.numeric(starttime)
if(calltime < timepercall){
Sys.sleep(timepercall - calltime)
}
page.df = jsonlite::fromJSON(rawToChar(d$content))
rm(starttime, endtime, calltime, URL, d)
# Start assembling output data frame (called "result")
result = as.data.frame(page.df)
result$X.type <- NULL
result$`API Status` <- apistatus
result$X.type = NULL
result$`API Status` = apistatus
rm(apistatus)
result.list[[i]] = result
utils::setTxtProgressBar(pb, i)
Expand Down
6 changes: 2 additions & 4 deletions man/get_ULEZ.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ca0645b

Please sign in to comment.