Skip to content

rhwlo/humphrey

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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"))
	}
}

still to be done:

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).

About

A simple golang wrapper for the BART API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages