-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbart
More file actions
executable file
·33 lines (28 loc) · 1.01 KB
/
bart
File metadata and controls
executable file
·33 lines (28 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env nu
# Public key available from https://www.bart.gov/schedules/developers/api
# Add it to your .env like so "export BART_API_KEY={KEY}"
# Stations can be fetched from this API: https://api.bart.gov/docs/stn/stns.aspx
# Directions for all trains are 'North' or 'South'
let api_key = $env.BART_API_KEY # Add this to your .env file
let stationCode = 'ROCK'
let stationName = 'Rockridge'
let direction = 'South'
let msg = $"Next ($direction)bound trains from ($stationName):"
print $msg
http get $"https://api.bart.gov/api/etd.aspx?cmd=etd&orig=($stationCode)&key=($api_key)&json=y"
| $in.root.station
| first
| $in.etd.estimate
| flatten
| where direction == ($direction)
| insert bikes {|row| if (($row.bikeflag | str trim | into int) == 1) { "Yes" } else { "No" } }
| insert time {|row|
let mins = if ($row.minutes == "Leaving") {
0
} else {
$row.minutes | into int
}
(date now) + ($mins * 1min) | format date "%H:%M"
}
| select minutes time length bikes
| table --index false