Compare commits

...

3 Commits

4 changed files with 68 additions and 14 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
config.toml
.DS_Store

55
bus.go
View File

@ -6,25 +6,42 @@ import (
"io"
"net/http"
"net/url"
"strconv"
"time"
)
type Departure struct {
TripID int
RealtimeTripId string
StopHeadsign string
ArrivalTime time.Time
DepartureTime time.Time
RouteShortName string
TripID int
RealtimeTripId string
StopHeadsign string
ArrivalTime time.Time
DepartureTime time.Time
RealtimeArrivalTime time.Time
RealtimeDepartureTime time.Time
RouteShortName string
}
func (d Departure) HasRealtimeDepartureTime() bool {
return !d.RealtimeDepartureTime.IsZero()
}
func (d Departure) IsDelayed() bool {
if !d.HasRealtimeDepartureTime() {
return false
}
return d.RealtimeDepartureTime.After(d.DepartureTime)
}
type ResponseDeparture struct {
TripID int `json:"trip_id"`
RealtimeTripId string `json:"realtime_trip_id"`
StopHeadsign string `json:"stop_headsign"`
ArrivalTime string `json:"arrival_time"`
DepartureTime string `json:"departure_time"`
Tripdata struct {
TripID int `json:"trip_id"`
RealtimeTripId string `json:"realtime_trip_id"`
StopHeadsign string `json:"stop_headsign"`
ArrivalTime string `json:"arrival_time"`
DepartureTime string `json:"departure_time"`
RealtimeArrivalTime int `json:"realtime_arrival_time"`
RealtimeDepartureTime int `json:"realtime_departure_time"`
Tripdata struct {
Route struct {
RouteShortName string `json:"route_short_name"`
} `json:"route"`
@ -52,6 +69,20 @@ func (rd ResponseDeparture) ToDeparture() (Departure, error) {
}
departure.DepartureTime = _time
if rd.RealtimeArrivalTime != 0 {
_time, err = parseUnixTimestamp(strconv.Itoa(rd.RealtimeArrivalTime))
if err == nil {
departure.RealtimeArrivalTime = _time
}
}
if rd.RealtimeDepartureTime != 0 {
_time, err = parseUnixTimestamp(strconv.Itoa(rd.RealtimeDepartureTime))
if err == nil {
departure.RealtimeDepartureTime = _time
}
}
return departure, nil
}

View File

@ -30,7 +30,11 @@
<tr>
<td>{{ $val.RouteShortName }}</td>
<td>{{ $val.StopHeadsign }}</td>
{{ if $val.HasRealtimeDepartureTime }}
<td><time class="{{ if $val.IsDelayed }}delayed{{ else }}on-time{{ end }}">{{ formatTime $val.RealtimeDepartureTime }}</time></td>
{{ else }}
<td><time>{{ formatTime $val.DepartureTime }}</time></td>
{{ end }}
</tr>
{{ end }}
{{ end }}
@ -40,4 +44,4 @@
{{ end }}
</main>
</body>
</html>
</html>

View File

@ -43,4 +43,22 @@ td:first-child {
td:last-child {
padding-right: 0;
}
}
time {
background: black;
color: white;
display: inline-block;
font-size: .8rem;
padding: .2em .2em .1em;
}
.on-time {
background: green;
color: white;
}
.delayed {
background: red;
color: white;
}