Horrid station parsing
This commit is contained in:
26
bt.nim
26
bt.nim
@@ -27,6 +27,30 @@ proc lineColor(color: string): ForegroundColor =
|
||||
of "orange": fgMagenta
|
||||
else: fgDefault
|
||||
|
||||
# try to guess which station abbreviation I meant to type
|
||||
proc parseStation(station: string): string =
|
||||
case station:
|
||||
of "ashby": "ashb"
|
||||
of "antioch": "antioch"
|
||||
of "balboa": "balb"
|
||||
of "berkeley", "berkly": "dtbrk"
|
||||
of "civic", "cvc": "civc"
|
||||
of "uptown": "19th"
|
||||
of "emb", "embark": "embr"
|
||||
of "fmt", "fremont": "frmt"
|
||||
of "mcaurthur", "mcaurther": "mcar"
|
||||
of "montgomery": "mont"
|
||||
of "walnut": "wcrk"
|
||||
of "hwd", "hayward": "haywd"
|
||||
of "sfo": "sfia"
|
||||
of "oak": "oakl"
|
||||
of "orinda": "orin"
|
||||
of "millbrae", "mil": "mlbr"
|
||||
of "powell", "powel": "powl"
|
||||
of "rockridge": "rock"
|
||||
of "west": "woak"
|
||||
else: station
|
||||
|
||||
proc formatDepartures(etd: JSONNode): string =
|
||||
let name = etd["root"]["station"][0]["name"].getStr
|
||||
let lines = etd["root"]["station"][0]["etd"]
|
||||
@@ -57,7 +81,7 @@ proc main =
|
||||
if len(params) == 0:
|
||||
usage()
|
||||
elif len(params) == 1:
|
||||
let station = params[0]
|
||||
let station = parseStation(params[0])
|
||||
echo formatDepartures(getDepartures(station))
|
||||
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user