Sort departures by countdown
Some checks failed
Build image / build-image (push) Failing after 1m49s
Some checks failed
Build image / build-image (push) Failing after 1m49s
This commit is contained in:
parent
4a73099460
commit
f3120905fe
9
main.go
9
main.go
@ -1,5 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "cmp"
|
||||||
import "encoding/json"
|
import "encoding/json"
|
||||||
import "errors"
|
import "errors"
|
||||||
import "fmt"
|
import "fmt"
|
||||||
@ -97,6 +98,7 @@ func (c KVVEFAClient) BuildRequest(stopId string) (*http.Request, error) {
|
|||||||
form.Set("useRealtime", "1")
|
form.Set("useRealtime", "1")
|
||||||
form.Set("limit", "10")
|
form.Set("limit", "10")
|
||||||
form.Set("mode", "direct")
|
form.Set("mode", "direct")
|
||||||
|
form.Set("useRealtime", "1")
|
||||||
form.Set("outputFormat", "json")
|
form.Set("outputFormat", "json")
|
||||||
body := strings.NewReader(form.Encode())
|
body := strings.NewReader(form.Encode())
|
||||||
|
|
||||||
@ -179,6 +181,7 @@ type Departure struct {
|
|||||||
Symbol string `json:"symbol"`
|
Symbol string `json:"symbol"`
|
||||||
Direction string `json:"direction"`
|
Direction string `json:"direction"`
|
||||||
Leaving string `json:"leaving"`
|
Leaving string `json:"leaving"`
|
||||||
|
Countdown int
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseDepartures(response DMResponse, allowedPlatform *string) (Departures, error) {
|
func ParseDepartures(response DMResponse, allowedPlatform *string) (Departures, error) {
|
||||||
@ -223,9 +226,14 @@ func ParseDepartures(response DMResponse, allowedPlatform *string) (Departures,
|
|||||||
d.ServingLine.Symbol,
|
d.ServingLine.Symbol,
|
||||||
direction,
|
direction,
|
||||||
leaving,
|
leaving,
|
||||||
|
countdown,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
slices.SortFunc(ds, func(a Departure, b Departure) int {
|
||||||
|
return cmp.Compare(a.Countdown, b.Countdown)
|
||||||
|
})
|
||||||
|
|
||||||
return Departures{ds}, nil
|
return Departures{ds}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,6 +273,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
c := efaClients[(efaClient.Add(1) - 1) % uint64(len(efaClients))]
|
c := efaClients[(efaClient.Add(1) - 1) % uint64(len(efaClients))]
|
||||||
|
log.Print(c.GetName())
|
||||||
ds, err := FetchDepartures(c, stopId)
|
ds, err := FetchDepartures(c, stopId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user