knitr::opts_chunk$set(echo = TRUE)
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:
install.packages("rflights")
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")$node nrow(arg_id) # only one result, so it might be the one colnames(arg_id) arg_id$id arg_id$region$continent$id arg_id <- arg_id$id tl_id <- find_location("toulouse")$node nrow(tl_id) tl_id$typename # we are looking for the city tl_id <- tl_id[tl_id$typename == "City", ] tl_id$country$name tl_id <- tl_id$id
# get flights from Argentina to toulouse for this month flights <- get_flights( fly_from = "Country:AR", fly_to = "City:toulouse_fr", departure_from = Sys.Date(), departure_to = Sys.Date() + 30 ) nrow(flights$itineraries) head(flights$itineraries$price$amount)
Find plane tickets from my city to anywhere, from today to 2 next weeks.
# I am a nomad, let's go anywhere! flights <- search_flights( fly_from = "Country:AR", departure_from = Sys.Date(), departure_to = Sys.Date() + 2 * 7 ) nrow(flights$itineraries) head(data.frame( from = flights$itineraries$source$station$name, to = flights$itineraries$destination$station$name, price = flights$itineraries$price$amount ))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.