initial commit

This commit is contained in:
2026-06-13 09:11:52 +02:00
parent 6b170cf12b
commit 3b84fad254
5 changed files with 155 additions and 9 deletions

43
internal/maps/trips.go Normal file
View File

@@ -0,0 +1,43 @@
package maps
import (
"encoding/json"
"log"
"net/http"
"shellixa/puvetra/internal/types"
"time"
)
func GetTrips() []types.MapTrip {
client := http.Client{}
req, err := http.NewRequest("GET", "https://api.transitous.org/api/v1/map/trips", nil)
if err != nil {
log.Fatal(err)
}
q := req.URL.Query()
now := time.Now().Format(time.RFC3339)
q.Add("startTime", now)
q.Add("endTime", now)
q.Add("min", "51.1626,13.5609")
q.Add("max", "50.9973,13.8596")
q.Add("zoom", "14")
q.Add("precision", "2")
req.URL.RawQuery = q.Encode()
response, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
defer response.Body.Close()
var trips []types.MapTrip
if err := json.NewDecoder(response.Body).Decode(&trips); err != nil {
log.Fatal(err)
}
return trips
}

63
internal/types/types.go Normal file
View File

@@ -0,0 +1,63 @@
package types
type TripMeta struct {
TripId string
RouteShortName string
DisplayName string `json:"omitempty"`
}
type MapTrip struct {
Trips []TripMeta
RouteColor string
Mode string
Distance float32
Departure string
Arrival string
From Place
To Place
ScheduledDeparture string
ScheduledArrival string
RealTime bool
Polyline string
}
type Trip struct {
Duration int64
StartTime string
EndTine string
Transfers int
Id string
Legs []TripLeg
}
type TripLeg struct {
Mode string
From Place
To Place
Duration int64
StartTime string
EndTime string
ScheduledStartTime string
ScheduledEndTime string
RealTime bool
Scheduled bool
Distance float32
Headsign string
TripFrom Place
TripTo Place
}
type Place struct {
Name string
StopId string
Lat float32
Lon float32
Arrival string
Departure string
Track string
StopCode string
Description string
Cancelled bool
Modes []string
}