-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbusroutes.go
89 lines (79 loc) · 2.38 KB
/
busroutes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
// Stop representing a bus stop
type Stop struct {
RouteID string `json:"routeID"`
DirectionID int `json:"directionID"`
StopID int `json:"stopID"`
TimePointID int `json:"timePointID"`
}
// BusStopRequest payload
type BusStopRequest struct {
Stops []Stop `json:"stops"`
}
// Crossings represents time data for a stop
type Crossings struct {
Cancelled bool `json:"cancelled"`
SchedTime string `json:"schedTime"`
SchedPeriod string `json:"schedPeriod"`
PredTime string `json:"predTime"`
PredPeriod string `json:"predPeriod"`
Countdown string `json:"countdown"`
Destination string `json:"destination"`
}
// StopsResponse represents a stop in a response
type StopsResponse struct {
DirectionID int `json:"directionID"`
StopID int `json:"stopID"`
TimePointID int `json:"timePointID"`
SameDestination bool `json:"sameDestination"`
Crossings []Crossings `json:"crossings"`
}
// RouteStops represents a list of bus stops
type RouteStops struct {
RouteID int `json:"routeID"`
Stops []StopsResponse `json:"stops"`
}
// BusStopResponseData represents the data from a response
type BusStopResponseData struct {
ErrorMessage string `json:"errorMessage"`
ShowArrivals bool `json:"showArrivals"`
ShowStopNumber bool `json:"showStopNumber"`
ShowScheduled bool `json:"showScheduled"`
ShowDestination bool `json:"showDestination"`
UpdateTime string `json:"updateTime"`
UpdatePeriod string `json:"updatePeriod"`
RouteStops []RouteStops `json:"routeStops"`
}
// BusStopResponse represents a response object
type BusStopResponse struct {
Data BusStopResponseData `json:"d"`
}
func main() {
payload := BusStopRequest{
Stops: []Stop{
Stop{
RouteID: "83",
DirectionID: 17,
StopID: 524,
TimePointID: 0,
},
},
}
b := new(bytes.Buffer)
json.NewEncoder(b).Encode(payload)
res, _ := http.Post("http://webwatch.lavta.org/tmwebwatch/GoogleMap.aspx/getStopTimes", "application/json", b)
body := BusStopResponse{}
json.NewDecoder(res.Body).Decode(&body)
stopTimes := body.Data.RouteStops[0].Stops[0].Crossings
fmt.Println("Next stop times: ")
for _, time := range stopTimes {
fmt.Printf("%v%s, ", time.PredTime, time.PredPeriod)
}
fmt.Print("\n")
}