Initial commit
This commit is contained in:
16
actransit.nim
Normal file
16
actransit.nim
Normal file
@@ -0,0 +1,16 @@
|
||||
import std/[httpclient, json, sequtils, strutils, sugar]
|
||||
import strformat
|
||||
|
||||
const API_KEY = "04F93AE4667F331EFD05EF31A2FF7DF6"
|
||||
|
||||
proc get_predictions*(client: HTTPClient, stop: string, route: string): JSONNode =
|
||||
let url = &"https://api.actransit.org/transit/actrealtime/prediction?token={API_KEY}&stpid={stop}&rt={route}"
|
||||
let response = client.getContent(url)
|
||||
let prediction = parseJson(response)
|
||||
prediction["bustime-response"]
|
||||
|
||||
proc format_predictions*(prd: JSONNode): string =
|
||||
if not prd.hasKey("prd"):
|
||||
"No prediction available"
|
||||
else:
|
||||
prd["prd"].getElems.map(time => time["prdctdn"].getStr).join(", ")
|
||||
Reference in New Issue
Block a user