From a563cc45b5069a93ba88e85b6d68cd227911a695 Mon Sep 17 00:00:00 2001 From: Paul Brinkmeier Date: Sun, 27 Apr 2025 15:30:45 +0200 Subject: [PATCH] Add VAGEFAClient --- README.md | 1 + flake.nix | 2 +- main.go | 35 ++++++++++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7938c23..ac179db 100644 --- a/README.md +++ b/README.md @@ -11,3 +11,4 @@ - [x] Transfer using JSON - [x] Correctly implement basic auth - [ ] Use unidecode to replace non-ascii stuff in the backend +- [ ] Add query parameter for selecting EFAClient diff --git a/flake.nix b/flake.nix index b892edb..9db9116 100644 --- a/flake.nix +++ b/flake.nix @@ -16,7 +16,7 @@ vrnp-static = pkgs.buildGoModule { pname = "vrnp"; - version = "0.0.8"; + version = "0.0.9"; vendorHash = null; # For building the package, we use only the files not ignored by Git as inputs. diff --git a/main.go b/main.go index 0b6b41a..096ae22 100644 --- a/main.go +++ b/main.go @@ -55,6 +55,7 @@ var allEfaClients []EFAClient = []EFAClient{ BwegtEFAClient{}, VRNEFAClient{}, KVVEFAClient{}, + VAGEFAClient{}, } type VRNEFAClient struct { @@ -151,6 +152,38 @@ func (c BwegtEFAClient) BuildRequest(stopId string) (*http.Request, error) { return req, nil } +type VAGEFAClient struct { +} + +func (c VAGEFAClient) GetName() string { + return "VAG" +} + +func (c VAGEFAClient) BuildRequest(stopId string) (*http.Request, error) { + // Create request object + req, err := http.NewRequest("GET", "https://efa.vagfr.de/vagfr3/XSLT_DM_REQUEST", nil) + if err != nil { + return nil, err + } + + // Configure our request + query := url.Values{} + query.Set("coordOutputFormat", "EPSG:4326") + query.Set("depType", "stopEvents") + query.Set("includeCompleteStopSeq", "0") + query.Set("limit", "10") + query.Set("locationServerActive", "0") + query.Set("mode", "direct") + query.Set("name_dm", stopId) + query.Set("outputFormat", "json") + query.Set("type_dm", "stop") + query.Set("useOnlyStops", "1") + query.Set("useRealtime", "1") + req.URL.RawQuery = query.Encode() + + return req, nil +} + func FetchDepartures(c EFAClient, stopId string) (DMResponse, error) { req, err := c.BuildRequest(stopId) if err != nil { @@ -281,7 +314,7 @@ func main() { platform = &query["platform"][0] } - c := efaClients[(efaClient.Add(1)-1)%uint64(len(efaClients))] + c := efaClients[(efaClient.Add(1) - 1) % uint64(len(efaClients))] ds, err := FetchDepartures(c, stopId) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError)