Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
72734c7faa | ||
|
|
5deb037fe5 | ||
|
|
6e78235127 | ||
|
|
5d5b893948 | ||
|
|
4a73099460 | ||
|
|
addc90d856 | ||
|
|
d23be3062a |
+10
-5
@@ -176,14 +176,19 @@ void logic_loop() {
|
||||
|
||||
int line = 0;
|
||||
for (JsonVariant departure : departures["departures"].as<JsonArray>()) {
|
||||
const char *directionStr = departure["direction"].as<const char *>();
|
||||
|
||||
display.setCursor(MAIN_X, MAIN_Y + (CY + 3) * line);
|
||||
display.printf("%2s %-15.15s %6s",
|
||||
display.printf("%2s %-15.15s ",
|
||||
departure["symbol"].as<const char*>(),
|
||||
directionStr,
|
||||
departure["leaving"].as<const char*>()
|
||||
departure["direction"].as<const char *>()
|
||||
);
|
||||
if (departure["leaving"].as<String>().equals("sofort")) {
|
||||
int16_t x = display.getCursorX();
|
||||
int16_t y = display.getCursorY();
|
||||
display.drawBitmap(x + 6 * CX - tiny_train_dims[0], y, tiny_train[0], tiny_train_dims[0], tiny_train_dims[1], COLOR_TEXT);
|
||||
} else {
|
||||
display.printf("%6s", departure["leaving"].as<const char*>());
|
||||
}
|
||||
|
||||
line++;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
vrnp-static = pkgs.buildGoModule {
|
||||
pname = "vrnp";
|
||||
version = "0.0.5";
|
||||
version = "0.0.8";
|
||||
vendorHash = null;
|
||||
|
||||
# For building the package, we use only the files not ignored by Git as inputs.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package main
|
||||
|
||||
import "cmp"
|
||||
import "encoding/json"
|
||||
import "errors"
|
||||
import "fmt"
|
||||
@@ -50,6 +51,12 @@ type EFAClient interface {
|
||||
BuildRequest(string) (*http.Request, error)
|
||||
}
|
||||
|
||||
var allEfaClients []EFAClient = []EFAClient{
|
||||
BwegtEFAClient{},
|
||||
VRNEFAClient{},
|
||||
KVVEFAClient{},
|
||||
}
|
||||
|
||||
type VRNEFAClient struct {
|
||||
}
|
||||
|
||||
@@ -97,6 +104,7 @@ func (c KVVEFAClient) BuildRequest(stopId string) (*http.Request, error) {
|
||||
form.Set("useRealtime", "1")
|
||||
form.Set("limit", "10")
|
||||
form.Set("mode", "direct")
|
||||
form.Set("useRealtime", "1")
|
||||
form.Set("outputFormat", "json")
|
||||
body := strings.NewReader(form.Encode())
|
||||
|
||||
@@ -179,6 +187,7 @@ type Departure struct {
|
||||
Symbol string `json:"symbol"`
|
||||
Direction string `json:"direction"`
|
||||
Leaving string `json:"leaving"`
|
||||
Countdown int `json:"-"`
|
||||
}
|
||||
|
||||
func ParseDepartures(response DMResponse, allowedPlatform *string) (Departures, error) {
|
||||
@@ -223,24 +232,32 @@ func ParseDepartures(response DMResponse, allowedPlatform *string) (Departures,
|
||||
d.ServingLine.Symbol,
|
||||
direction,
|
||||
leaving,
|
||||
countdown,
|
||||
})
|
||||
}
|
||||
|
||||
slices.SortFunc(ds, func(a Departure, b Departure) int {
|
||||
return cmp.Compare(a.Countdown, b.Countdown)
|
||||
})
|
||||
|
||||
return Departures{ds}, nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
password := os.Getenv("VRNP_PASSWORD")
|
||||
if len(password) == 0 {
|
||||
panic("Required environment variable VRNP_PASSWORD is not set")
|
||||
log.Fatal("Required environment variable VRNP_PASSWORD is not set")
|
||||
}
|
||||
|
||||
clientAllowlist := strings.Split(os.Getenv("VRNP_CLIENT_ALLOWLIST"), ",")
|
||||
|
||||
// Use round-robin to send incoming requests to different servers
|
||||
var efaClient atomic.Uint64
|
||||
efaClients := []EFAClient{
|
||||
BwegtEFAClient{},
|
||||
VRNEFAClient{},
|
||||
KVVEFAClient{},
|
||||
var efaClients []EFAClient
|
||||
for _, efaClient := range allEfaClients {
|
||||
if len(clientAllowlist) != 0 && slices.Contains(clientAllowlist, efaClient.GetName()) {
|
||||
efaClients = append(efaClients, efaClient)
|
||||
}
|
||||
}
|
||||
|
||||
http.HandleFunc("/departures", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user