Skip to contents

Collect GTFS-RT data from a JSON feed at regular intervals

Usage

rt_collect_json(
  gtfs_rt_url,
  destination_file,
  header_key = "header",
  entity_key = "entity",
  fields_collect = c("id", "vehicle.trip.trip_id", "vehicle.position.latitude",
    "vehicle.position.longitude", "vehicle.position.speed", "vehicle.timestamp",
    "vehicle.current_status", "vehicle.current_stop_sequence", "vehicle.stop_id"),
  scrape_interval = 60,
  log_file = NA
)

Arguments

gtfs_rt_url

String. URL of the GTFS-RT feed in JSON format.

destination_file

String. File to save the downloaded GTFS-RT data. Content is appended in each iteration.

header_key

String (Default "header"). Key in the JSON corresponding to the feed header. Set to NA if not present.

entity_key

String (Default "entity"). Key in the JSON corresponding to the feed entities. Set to NA if response is a flat list.

fields_collect

Character vector. Fields to extract from each entity in the feed.

scrape_interval

Integer (Default 60). Interval in seconds between each download. Negative to run only once.

log_file

String (Optional). Path to a log file to save download logs.

Details

Downloads GTFS-RT data from the specified URL at regular intervals and saves them to the destination file.

This function will run indefinitely until manually stopped (CTRL + C).

Examples

if (FALSE) { # \dontrun{
GTFShift::rt_collect_json("https://api.example.com/gtfs-rt", "gtfs_rt_data.csv")
} # }