humphrey is a Go library written for BART’s API and named after the award-winning free BART transportation to Berkeley of yesteryear.
// an example
import (
"fmt"
"log"
"strings"
"github.com/rhwlo/humphrey"
)
func main() {
stationMap := make(map[string]humphrey.Station)
routeMap := make(map[string]humphrey.Route)
routes, err := humphrey.DefaultClient.GetCurrentRoutes()
if err != nil {
log.Fatal(err)
}
for _, route := range routes {
routeMap[route.ID] = route
}
stations, err := humphrey.DefaultClient.GetAllStations()
if err != nil {
log.Fatal(err)
}
for _, station := range stations {
stationMap[station.Abbreviation] = station
}
trains, err := humphrey.DefaultClient.GetStationSchedule(stationMap["MCAR"])
if err != nil {
log.Fatal(err)
}
for _, train := range trains {
stationNames := strings.Split(routeMap[train.Line].Abbreviation, "-")
sourceStation := stationMap[stationNames[0]]
destStation := stationMap[stationNames[1]]
trainID := fmt.Sprintf("#%d on %s", train.Index, strings.ToLower(train.Line))
fmt.Printf("Train %s (headed from %s to %s) is scheduled to pass %s at %s\n", trainID, sourceStation.Name, destStation.Name, stationMap["MCAR"].Name, train.Time.Format("3:04 PM"))
}
}
- I’d like to wrap the
sched/load
call, but it looks a little tricky - I’d like to wrap the
sched/special
andsched/holiday
calls into one function called something likeClient.GetScheduleIrregularities()
- I might want to wrap the calls for
sched/arrive
andsched/depart
, though it sounds (by BART’s own admission) like BART deals with time in a creative way.
I deliberately left out the stn/stninfo
and stn/stnaccess
calls because most of the information they provide is either provided elsewhere or is in a format intended to be presented through a web browser (i.e., formatted HTML).