From ad6c6b127f72fe44c5c92716982ddb4ce27824d8 Mon Sep 17 00:00:00 2001 From: Zoe Moore Date: Tue, 28 Jun 2022 17:32:05 -0700 Subject: [PATCH] Horrid station parsing --- bt.nim | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/bt.nim b/bt.nim index 1ee3125..d944dfd 100644 --- a/bt.nim +++ b/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()