From b9208930976d8b802cd45550d5f681489029653e Mon Sep 17 00:00:00 2001 From: Jasper Bok Date: Sun, 6 Aug 2023 23:18:47 +0200 Subject: [PATCH] Add 'interesting routes' to quays This way only the routes we're actually interested in will be displayed. --- bus.go | 5 ++++- main.go | 22 +++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/bus.go b/bus.go index 8ec9597..a95801e 100644 --- a/bus.go +++ b/bus.go @@ -103,7 +103,10 @@ func getDepartures(quay Quay) ([]Departure, error) { if err != nil { return departures, err } - departures = append(departures, d) + + if quay.IsInterestingDeparture(d) { + departures = append(departures, d) + } } } diff --git a/main.go b/main.go index 544058f..909e377 100644 --- a/main.go +++ b/main.go @@ -4,10 +4,26 @@ import ( "net/http" ) +type Route struct { + RouteShortName string `json:"route_short_name"` + RouteLongName string `json:"route_long_name"` +} + type Quay struct { - ID string `json:"quayid"` - Name string `json:"name"` - Town string `json:"town"` + ID string `json:"quayid"` + Name string `json:"name"` + Town string `json:"town"` + RoutesOfInterest []Route +} + +func (q Quay) IsInterestingDeparture(d Departure) bool { + for _, route := range q.RoutesOfInterest { + if (route.RouteShortName == d.RouteShortName) && (route.RouteLongName == d.StopHeadsign) { + return true + } + } + + return false } var BusClient *http.Client