Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/kurtraschke/gtfs-rt-dump

Command-line dumper for GTFS-realtime feeds
https://github.com/kurtraschke/gtfs-rt-dump

Last synced: about 2 months ago
JSON representation

Command-line dumper for GTFS-realtime feeds

Lists

README

        

gtfs-rt-dump
============

Command-line dumper for GTFS-realtime feeds.

```
$ java -jar gtfs-rt-dump.jar -h
Usage: gtfs-rt-dump [-hV] [--disable-tls-validation] [-H=]...
[-X=]... [-f= |
-u=] [-U= -P=] COMMAND
Parse and display the contents of a GTFS-realtime feed in a human-readable
format.
--disable-tls-validation
Disable all TLS server certificate validation.
-h, --help Show this help message and exit.
-H, --header=
Add specified HTTP header to request.
-V, --version Print version information and exit.
-X, --enable-extension=
Enable specified GTFS-rt extensions. Valid values:
OBA, NYCT, LIRR, MNR, MTARR, MERCURY
Input can be read from a file or URL. If neither are specified, standard input
will be used.
-f, --file= Read GTFS-rt from specified file.
-u, --url= Read GTFS-rt from specified URL.
HTTP Basic authentication credentials can be specified if input is read from a
URL.
-P, --password= Password for HTTP Basic authentication
-U, --username= Username for HTTP Basic authentication
Commands:
help Displays help information about the specified command
pbtext Protocol Buffer text format output
table Formatted table output
json JSON output
csv CSV output

```

If pbtext or formatted table output is selected, the timestamp format can be specified:

```
$ java -jar gtfs-rt-dump.jar help table
Usage: gtfs-rt-dump table [--timestamp-format=]
Formatted table output
--timestamp-format=
Valid values: POSIX, ISO_8601_LOCAL, ISO_8601_UTC
```

```
Usage: gtfs-rt-dump pbtext [--timestamp-format[=]]
Protocol Buffer text format output
--timestamp-format[=]
Valid values: POSIX, ISO_8601_LOCAL, ISO_8601_UTC
```

To produce formatted timestamps in a timezone other than the OS timezone, set the `user.timezone` Java system property:

```
java -Duser.timezone="US/Pacific" -jar gtfs-rt-dump.jar -u http://api.bart.gov/gtfsrt/tripupdate.aspx pbtext --timestamp-format
```

For CSV output, a single feed component must be specified for extraction:

```
% java -jar gtfs-rt-dump.jar help csv
Usage: gtfs-rt-dump csv
CSV output
Feed part to extract to CSV. Valid values:
FEED_HEADER, TRIP_UPDATES, VEHICLE_POSITIONS,
ALERTS

```

Sample usage:

```
$ java -jar gtfs-rt-dump.jar -u http://api.bart.gov/gtfsrt/tripupdate.aspx pbtext
header {
gtfs_realtime_version: "1.0"
incrementality: FULL_DATASET
timestamp: 1418867234
}
entity {
id: "46DC10"
trip_update {
trip {
trip_id: "46DC10"
}
```

The JSON output mode can be combined with [jq](https://stedolan.github.io/jq/) to slice and filter the resulting output:

```
$ java -jar gtfs-rt-dump.jar -u http://api.bart.gov/gtfsrt/tripupdate.aspx json | jq '[.entity[].tripUpdate | .trip.tripId as $tripId | .stopTimeUpdate[] | {tripId: $tripId, stopId: .stopId, arrival: .arrival.time|todate}] | map(select(.stopId == "EMBR")) | sort_by(.arrival) | .[0:3]'
[
{
"tripId": "4531853SAT",
"stopId": "EMBR",
"arrival": "2020-01-19T03:12:04Z"
},
{
"tripId": "1071858SAT",
"stopId": "EMBR",
"arrival": "2020-01-19T03:16:42Z"
},
{
"tripId": "3611847SAT",
"stopId": "EMBR",
"arrival": "2020-01-19T03:19:57Z"
}
]
```