make it work for my tram board
adds webserer with endpoint /line?number=3 you need to specify a post body text using b64-encoded, semicolon-separated names of the stops index of stop name corresponds to returned value (led index)
This commit is contained in:
@@ -2,6 +2,7 @@ package maps
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"shellixa/puvetra/internal/types"
|
||||
@@ -16,9 +17,12 @@ func GetTrips() []types.MapTrip {
|
||||
}
|
||||
q := req.URL.Query()
|
||||
|
||||
now := time.Now().Format(time.RFC3339)
|
||||
q.Add("startTime", now)
|
||||
q.Add("endTime", now)
|
||||
now := time.Now()
|
||||
delta := time.Minute * 5
|
||||
lowerBound := now.Add(-delta).Format(time.RFC3339)
|
||||
upperBound := now.Add(delta).Format(time.RFC3339)
|
||||
q.Add("startTime", lowerBound)
|
||||
q.Add("endTime", upperBound)
|
||||
q.Add("min", "51.1626,13.5609")
|
||||
q.Add("max", "50.9973,13.8596")
|
||||
q.Add("zoom", "14")
|
||||
@@ -34,9 +38,11 @@ func GetTrips() []types.MapTrip {
|
||||
defer response.Body.Close()
|
||||
|
||||
var trips []types.MapTrip
|
||||
if err := json.NewDecoder(response.Body).Decode(&trips); err != nil {
|
||||
buffer, _ := io.ReadAll(response.Body)
|
||||
if err = json.Unmarshal(buffer, &trips); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Printf("component='Transitous API' message='Response was %d bytes'", len(buffer))
|
||||
|
||||
return trips
|
||||
|
||||
|
||||
34
internal/timetable/trips.go
Normal file
34
internal/timetable/trips.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package timetable
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"shellixa/puvetra/internal/types"
|
||||
)
|
||||
|
||||
func GetTrip(tripId string) types.Trip {
|
||||
client := http.Client{}
|
||||
url := fmt.Sprintf("https://api.transitous.org/api/v6/trip?tripId=%s", tripId)
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
response, err := client.Do(req)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
defer response.Body.Close()
|
||||
|
||||
var trip types.Trip
|
||||
if err := json.NewDecoder(response.Body).Decode(&trip); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
return trip
|
||||
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package types
|
||||
|
||||
import "time"
|
||||
|
||||
|
||||
type TripMeta struct {
|
||||
TripId string
|
||||
@@ -12,20 +14,20 @@ type MapTrip struct {
|
||||
RouteColor string
|
||||
Mode string
|
||||
Distance float32
|
||||
Departure string
|
||||
Arrival string
|
||||
Departure time.Time
|
||||
Arrival time.Time
|
||||
From Place
|
||||
To Place
|
||||
ScheduledDeparture string
|
||||
ScheduledArrival string
|
||||
ScheduledDeparture time.Time
|
||||
ScheduledArrival time.Time
|
||||
RealTime bool
|
||||
Polyline string
|
||||
}
|
||||
|
||||
type Trip struct {
|
||||
Duration int64
|
||||
StartTime string
|
||||
EndTine string
|
||||
StartTime time.Time
|
||||
EndTine time.Time
|
||||
Transfers int
|
||||
Id string
|
||||
Legs []TripLeg
|
||||
@@ -36,10 +38,10 @@ type TripLeg struct {
|
||||
From Place
|
||||
To Place
|
||||
Duration int64
|
||||
StartTime string
|
||||
EndTime string
|
||||
ScheduledStartTime string
|
||||
ScheduledEndTime string
|
||||
StartTime time.Time
|
||||
EndTime time.Time
|
||||
ScheduledStartTime time.Time
|
||||
ScheduledEndTime time.Time
|
||||
RealTime bool
|
||||
Scheduled bool
|
||||
Distance float32
|
||||
@@ -53,8 +55,8 @@ type Place struct {
|
||||
StopId string
|
||||
Lat float32
|
||||
Lon float32
|
||||
Arrival string
|
||||
Departure string
|
||||
Arrival time.Time
|
||||
Departure time.Time
|
||||
Track string
|
||||
StopCode string
|
||||
Description string
|
||||
|
||||
Reference in New Issue
Block a user