Query plane tickets, from several airlines, using the Kiwi API (similar to Google Flights).
The API is documented at https://docs.kiwi.com/.
You can install the rflights
package from CRAN:
Or get the latest version from GitHub:
if (!require("remotes")) {
install.packages("remotes")
}
remotes::install_github("jcrodriguez1989/rflights")
library("rflights")
# get Argentina and toulouse IDs
arg_id <- find_location("Argentina", "country")
length(arg_id) # only one result, so it might be the one
## [1] 1
## [1] "id" "active" "code"
## [4] "name" "slug" "alternative_names"
## [7] "rank" "global_rank_dst" "neighbours"
## [10] "organizations" "currency" "region"
## [13] "continent" "location" "type"
## [1] "AR"
## $id
## [1] "south-america"
##
## $code
## [1] "SA"
##
## $name
## [1] "South America"
##
## $slug
## [1] "south-america"
## [1] 5
## [[1]]
## [1] "city"
##
## [[2]]
## [1] "airport"
##
## [[3]]
## [1] "bus_station"
##
## [[4]]
## [1] "tourist_region"
##
## [[5]]
## [1] "bus_station"
# we are looking for the city
tl_id <- tl_id[[which(sapply(tl_id, function(x) x$type == "city"))]]
tl_id$country
## $id
## [1] "FR"
##
## $name
## [1] "France"
##
## $slug
## [1] "france"
##
## $code
## [1] "FR"
## [1] "toulouse_fr"
# get flights from Argentina to toulouse around 01 July to 09 July
# Maybe I can go to the user2019??
flights <- get_flights(
fly_from = "AR", fly_to = "toulouse_fr",
date_from = "01/09/2019", date_to = "09/09/2019"
)
length(flights)
names(flights[[1]])
sapply(flights, function(x) x$price)
I used it to alert through a Pushbullet message.
my_savings <- 25 # yup, just 25USD
found_ticket <- FALSE
while (!found_ticket) {
flights <- get_flights(
fly_from = "AR", fly_to = "toulouse_fr",
date_from = "01/09/2019", date_to = "09/09/2019"
)
flights <- flights[sapply(flights, function(x) x$price) <= my_savings]
if (length(flights) > 0) {
send_alert(paste0(
"There is a plane ticket you can afford!\n",
"Check it out at Kiwi.com"
))
# user-defined alert function (not in rflights)
}
}
Find plane tickets from my city to anywhere, from today to 2 next weeks.
# I am a freelancer, let's go anywhere!
flights <- get_flights(
fly_from = "GNV",
date_from = Sys.Date(), date_to = Sys.Date() + 2 * 7
)
length(flights)
## [1] 99
## [,1] [,2]
## [1,] "91" "Nashville"
## [2,] "91" "Norfolk"
## [3,] "91" "Nashville"
## [4,] "94" "Pittsburgh"
## [5,] "112" "Raleigh"
## [6,] "122" "Washington, D.C."
## [7,] "123" "Boston"
## [8,] "123" "Orlando"
## [9,] "124" "Philadelphia"
## [10,] "124" "Cleveland"
## [11,] "124" "Providence"
## [12,] "125" "Indianapolis"
## [13,] "126" "Las Vegas"
## [14,] "128" "Chicago"
## [15,] "130" "Indianapolis"
## [16,] "132" "Nashville"
## [17,] "137" "Indianapolis"
## [18,] "137" "Orlando"
## [19,] "139" "Miami"
## [20,] "140" "Philadelphia"