EFA Departure Monitor on the command line

I just hacked together a small shell script that gets departures from my local public transportation service. It will list upcoming departures at a stop. You can find the script here.

Getting Started

You can either use the stop name:

$ ./efa-dm.sh "Dortmund Hbf"

Or you can use the stop ID:

$ ./efa-dm.sh 20000131

By default, it will simply print upcoming departures as a tab-separated list.

$ ./efa-dm.sh -n 3 "Essen Rüttenscheider Stern"
1       2018    3       5       16      20      2018    3       5       16      21      101     Essen Helenenstr.
2       2018    3       5       16      21      2018    3       5       16      22      108     Essen Altenessen Bf Schleife
2       2018    3       5       16      22                                              U11     Essen Messe W.-Süd/Gruga
Column Meaning
1 minutes left until departure
2 scheduled departure (year)
3 scheduled departure (month)
4 scheduled departure (day)
5 scheduled departure (hour)
6 scheduled departure (minute)
6 predicted actual departure (year)
8 predicted actual departure (month)
9 predicted actual departure (day)
10 predicted actual departure (hour)
11 predicted actual departure (minute)
12 line name
13 direction

You can also use the -p flag to get the pretty-printed version:

$ ./efa-dm.sh -p -n 3 "Essen Rüttenscheider Stern"
16:20(+1) 101 Essen Helenenstr. in 1 min
16:21 108 Essen Altenessen Bf Schleife in 1 min
16:22 U11 Essen Messe W.-Süd/Gruga in 2 min

Usage

Here's a list of all command line options:

$ ./efa-dm.sh -h
Usage: ./efa-dm.sh [-p] [-d] [-a <API_ENDPOINT>] [-n <NUM_DEPARTS>] [-t <TIME_OFFSET>] <STOP_NAME>
Options:
  -h                 Show this help
  -p                 Petty-printed output (instead of tab-separated values)
  -d                 Debug mode (output server reply and exit)
  -a <API_ENDPOINT>  Use API endpoint at this URL
  -n <NUM_DEPARTS>   Limit the number of departures (default: 8)
  -t <TIME_OFFSET>   Skip departures in next X minutes (default: 0)

Services that use EFA

Here's a list of other public transportation services that also use the Elektronische Fahrplanauskunft (EFA) system and thus can also by queried by the script as well:

Departure Monitor in Polybar

You can easily use this script as a polybar module:

[module/efa1]
type = custom/script
exec = /path/to/efa-dm.sh -p -t 4 -n 1 "Essen Hbf"
format = <label>
; In case this is a bus stop:
;  format =  <label>
; For a subway station:
;  format =  <label>
interval = 60