From 248f280e220a7dd44b7b6c79bb0ecb07504d4f5f Mon Sep 17 00:00:00 2001 From: Simon Rieger Date: Sat, 28 Sep 2024 13:39:46 +0200 Subject: [PATCH] =?UTF-8?q?Umgebungsvariable=20f=C3=BCr=20die=20Dauer=20un?= =?UTF-8?q?d=20zus=C3=A4tzliche=20Variablen=20f=C3=BCr=20Ferry,=20Tram=20u?= =?UTF-8?q?nd=20Taxi=20hinzuzuf=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 6 +++++- main.go | 23 ++++++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 2e28bdd..ed7926c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,8 +13,12 @@ services: - DB_NAME=traindb - DB_DSN=root:password@tcp(mariadb:3306)/traindb - API_BASE_URL=http://db-rest:3000 - - MAX_RESULTS=100 + - MAX_RESULTS=200 + - DURATION=240 - BUS=false + - FERRY=false + - TRAM=false + - TAXI=false # Hildesheim HBF, Braunschweig HBF, Hannover HBF - STATION_IDS=8000169,8000049,8000152 restart: always diff --git a/main.go b/main.go index f197574..b7330aa 100644 --- a/main.go +++ b/main.go @@ -43,10 +43,26 @@ func main() { if err != nil { log.Fatalf("Ungültiger Wert für MAX_RESULTS: %v", err) } + duration, err := strconv.Atoi(os.Getenv("DURATION")) + if err != nil { + log.Fatalf("Ungültiger Wert für DURATION: %v", err) + } includeBus, err := strconv.ParseBool(os.Getenv("BUS")) if err != nil { log.Fatalf("Ungültiger Wert für BUS: %v", err) } + includeFerry, err := strconv.ParseBool(os.Getenv("FERRY")) + if err != nil { + log.Fatalf("Ungültiger Wert für FERRY: %v", err) + } + includeTram, err := strconv.ParseBool(os.Getenv("TRAM")) + if err != nil { + log.Fatalf("Ungültiger Wert für TRAM: %v", err) + } + includeTaxi, err := strconv.ParseBool(os.Getenv("TAXI")) + if err != nil { + log.Fatalf("Ungültiger Wert für TAXI: %v", err) + } stationIDs := strings.Split(os.Getenv("STATION_IDS"), ",") db, err := sql.Open("mysql", dbDSN) @@ -57,7 +73,7 @@ func main() { for { for _, stationID := range stationIDs { - departures := fetchDepartures(apiBaseURL, stationID, maxResults, includeBus) + departures := fetchDepartures(apiBaseURL, stationID, maxResults, duration, includeBus, includeFerry, includeTram, includeTaxi) for _, dep := range departures { savePosition(db, dep) } @@ -66,8 +82,9 @@ func main() { } } -func fetchDepartures(apiBaseURL, stationID string, maxResults int, includeBus bool) []Departure { - url := fmt.Sprintf("%s/stops/%s/departures?results=%d&bus=%t", apiBaseURL, stationID, maxResults, includeBus) +func fetchDepartures(apiBaseURL, stationID string, maxResults, duration int, includeBus, includeFerry, includeTram, includeTaxi bool) []Departure { + url := fmt.Sprintf("%s/stops/%s/departures?results=%d&duration=%d&bus=%t&ferry=%t&tram=%t&taxi=%t", + apiBaseURL, stationID, maxResults, duration, includeBus, includeFerry, includeTram, includeTaxi) resp, err := http.Get(url) if err != nil { log.Printf("Fehler beim Abrufen der Abfahrten für Station %s: %v\n", stationID, err)