Initial commit
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
actransit
|
||||||
|
toolbox
|
||||||
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(", ")
|
||||||
83
toolbox.nim
Normal file
83
toolbox.nim
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
import gintro/[gtk4, gobject, gio, adw]
|
||||||
|
import std/[httpclient, with]
|
||||||
|
import strformat
|
||||||
|
import actransit
|
||||||
|
|
||||||
|
proc home_predictions: string =
|
||||||
|
let client = newHttpClient()
|
||||||
|
const home_nl = "51067"
|
||||||
|
const home_12 = "58995"
|
||||||
|
const home_29 = "56557"
|
||||||
|
|
||||||
|
let nl_predictions = client.get_predictions(home_nl, "NL").format_predictions
|
||||||
|
let twelve_predictions = client.get_predictions(home_12, "12").format_predictions
|
||||||
|
let twenty_nine_predictions = client.get_predictions(home_29, "29").format_predictions
|
||||||
|
|
||||||
|
&"Home\nNL: {nl_predictions}\n12: {twelve_predictions}\n29: {twenty_nine_predictions}"
|
||||||
|
|
||||||
|
proc office_predictions: string =
|
||||||
|
let client = newHttpClient()
|
||||||
|
const office_nl = "56565"
|
||||||
|
const office_12 = "57111"
|
||||||
|
|
||||||
|
let nl_predictions = client.get_predictions(office_nl, "NL").format_predictions
|
||||||
|
let twelve_predictions = client.get_predictions(office_12, "12").format_predictions
|
||||||
|
|
||||||
|
&"Oakland Office\nNL: {nl_predictions}\n12: {twelve_predictions}"
|
||||||
|
|
||||||
|
proc activate(app: adw.Application) =
|
||||||
|
let
|
||||||
|
window = adw.newApplicationWindow(app)
|
||||||
|
home_label = newLabel()
|
||||||
|
office_label = newLabel()
|
||||||
|
|
||||||
|
refresh_button = newButtonFromIconName("view-refresh")
|
||||||
|
header = adw.newHeaderBar()
|
||||||
|
mainBox = newBox(Orientation.vertical, 0)
|
||||||
|
with mainBox:
|
||||||
|
append header
|
||||||
|
append home_label
|
||||||
|
append office_label
|
||||||
|
|
||||||
|
with header:
|
||||||
|
pack_end refresh_button
|
||||||
|
|
||||||
|
with refresh_button:
|
||||||
|
iconName = "view-refresh"
|
||||||
|
|
||||||
|
with home_label:
|
||||||
|
text = home_predictions().cstring
|
||||||
|
marginTop = 10
|
||||||
|
marginBottom = 10
|
||||||
|
marginStart = 10
|
||||||
|
marginEnd = 10
|
||||||
|
|
||||||
|
with office_label:
|
||||||
|
text = office_predictions().cstring
|
||||||
|
marginTop = 10
|
||||||
|
marginBottom = 10
|
||||||
|
marginStart = 10
|
||||||
|
marginEnd = 10
|
||||||
|
|
||||||
|
proc button_refresh_signal(b: Button, labels: tuple[home: Label, office: Label]) =
|
||||||
|
labels.home.text = home_predictions().cstring
|
||||||
|
labels.office.text = office_predictions().cstring
|
||||||
|
|
||||||
|
refresh_button.connect("clicked", button_refresh_signal, (home_label, office_label))
|
||||||
|
|
||||||
|
with window:
|
||||||
|
title = "Toolbox"
|
||||||
|
defaultSize = (300, 500)
|
||||||
|
content = mainBox
|
||||||
|
show()
|
||||||
|
|
||||||
|
proc initAdw(app: adw.Application) =
|
||||||
|
adw.init()
|
||||||
|
|
||||||
|
proc main =
|
||||||
|
let app = adw.newApplication("space.quietfeathers.toolbox", {})
|
||||||
|
app.connect("startup", initAdw)
|
||||||
|
app.connect("activate", activate)
|
||||||
|
discard run(app)
|
||||||
|
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user