Compare commits

..

No commits in common. "ca83496e8a95d4b1f476401647be5d2e5703af30" and "4a4ee88c72c5a7fdd77a4d50734eb1c829d706d7" have entirely different histories.

4 changed files with 14 additions and 68 deletions

1
.gitignore vendored
View File

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

31
bus.go
View File

@ -6,7 +6,6 @@ import (
"io" "io"
"net/http" "net/http"
"net/url" "net/url"
"strconv"
"time" "time"
) )
@ -16,31 +15,15 @@ type Departure struct {
StopHeadsign string StopHeadsign string
ArrivalTime time.Time ArrivalTime time.Time
DepartureTime time.Time DepartureTime time.Time
RealtimeArrivalTime time.Time
RealtimeDepartureTime time.Time
RouteShortName string 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 { type ResponseDeparture struct {
TripID int `json:"trip_id"` TripID int `json:"trip_id"`
RealtimeTripId string `json:"realtime_trip_id"` RealtimeTripId string `json:"realtime_trip_id"`
StopHeadsign string `json:"stop_headsign"` StopHeadsign string `json:"stop_headsign"`
ArrivalTime string `json:"arrival_time"` ArrivalTime string `json:"arrival_time"`
DepartureTime string `json:"departure_time"` DepartureTime string `json:"departure_time"`
RealtimeArrivalTime int `json:"realtime_arrival_time"`
RealtimeDepartureTime int `json:"realtime_departure_time"`
Tripdata struct { Tripdata struct {
Route struct { Route struct {
RouteShortName string `json:"route_short_name"` RouteShortName string `json:"route_short_name"`
@ -69,20 +52,6 @@ func (rd ResponseDeparture) ToDeparture() (Departure, error) {
} }
departure.DepartureTime = _time 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 return departure, nil
} }

View File

@ -30,11 +30,7 @@
<tr> <tr>
<td>{{ $val.RouteShortName }}</td> <td>{{ $val.RouteShortName }}</td>
<td>{{ $val.StopHeadsign }}</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> <td><time>{{ formatTime $val.DepartureTime }}</time></td>
{{ end }}
</tr> </tr>
{{ end }} {{ end }}
{{ end }} {{ end }}

View File

@ -44,21 +44,3 @@ td:first-child {
td:last-child { td:last-child {
padding-right: 0; 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;
}