septa

package module
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 3, 2021 License: MIT Imports: 9 Imported by: 0

README

septa

Septa golang client and command line executable for getting the next regional rail train to arrive. This project uses https://www3.septa.org/api/

Build

Go Report Card golint

To build the command, clone this repo, then type make. The septa executable will be copied to $HOME/bin. Prerequisite is that you have docker installed, and $HOME/bin is on your $PATH.

git clone https://github.com/dherbst/septa
cd septa
make

You can create a bash alias to make looking up the next to arrive for your favorite stations:

alias nta="septa next Narberth \"Suburban Station\""

Alternatively, you can use the go install command which should install the septa binary to $HOME/go/bin:

git clone https://github.com/dherbst/septa
cd septa
make install-local
Download the binary

You can download the latest osx binary septa at https://github.com/dherbst/septa/releases. If you need a windows version please open an issue.

Commands

Next to Arrive - septa next <src> <dest>

Returns the next to arrive between the src and dest stations.

$ septa next Narberth "Suburban Station"

Paoli/Thorndale Train 5340 Departs  4:57PM Arrives  5:16PM On time
Paoli/Thorndale Train 1542 Departs  5:27PM Arrives  5:45PM On time
Paoli/Thorndale Train 5344 Departs  5:57PM Arrives  6:16PM On time
Paoli/Thorndale Train 5348 Departs  6:57PM Arrives  7:16PM On time
Paoli/Thorndale Train 5352 Departs  7:57PM Arrives  8:16PM On time
List of stations - septa stations

Returns the list of stations that are used as arguments in the next command.

$ septa stations

9th St
30th Street Station
49th St
Airport Terminal A
Airport Terminal B
...
Alerts - septa alerts [route]

Returns the alerts for all routes if no route specified, or just for the route specified.

$ septa alerts generic

Generic All SEPTA service will operate on a Sunday schedule on Friday, December 25 (Christmas Day). All SEPTA passengers are required to wear a face mask or covering. Regular service schedules are in effect, however, the Cynwyd and Chestnut Hill West Lines are suspended. The 12th & Filbert doors at Jefferson Station and the 16th & JFK doors at Suburban Station will be open during the following hours: 6:30 a.m. to 9:30 a.m. and 3:30 p.m. to 6:30 p.m. (Monday-Friday only). During all other hours these doors will be locked. We appreciate your patience during this time. With the launch of the SEPTA Key Card Travel Wallet feature for Regional Rail, the sale of paper tickets, single trip, and 10 trip strips ended <a href="http://septa.org/key/updates/paper-ticket-sales-ending.html">October 2, 2020</a>. Paper tickets will continue to be accepted through the valid date stamped on the back and valid for 180 days from the purchase date.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// GitHash is the sha hash of the current commit used to build this code.
	GitHash string
	// Version is the semantic version according to the release.
	Version string
)
View Source
var Routes = map[string]string{}/* 310 elements not displayed */

Routes is a map of the common name to the Route used in the API.

View Source
var Stations = []string{}/* 155 elements not displayed */

Stations is the list of valid station names for next to arrive

Functions

func IsValidStation

func IsValidStation(station string) bool

IsValidStation returns whether the station is a valid station.

Types

type APIBool added in v1.1.0

type APIBool bool

APIBool is a type of bool that can deal with the range of data that the Septa API returns for a bool which is any of "N", "Yes", "0", 0, etc.

func (*APIBool) UnmarshalJSON added in v1.1.0

func (item *APIBool) UnmarshalJSON(data []byte) error

UnmarshalJSON takes the values in JSON and maps them to the golang types. This is where N, No, etc are mapped to the bool type.

type AlertResult added in v1.1.0

type AlertResult struct {
	// Name3 is the three letter designation for the route.
	Name3             string  `json:"route"`
	RouteID           string  `json:"route_id"`
	RouteName         string  `json:"route_name"`
	Sequence          string  `json:"sequence"`
	Mode              string  `json:"mode"`
	IsAdvisory        APIBool `json:"isadvisory"`
	IsDetour          APIBool `json:"isdetour"`
	IsAlert           APIBool `json:"isalert"`
	IsSuspend         APIBool `json:"issuppend"`
	IsElevator        APIBool `json:"iselevator"`
	IsSuspended       APIBool `json:"issuspended"`
	IsStrike          APIBool `json:"isstrike"`
	IsModifiedService APIBool `json:"ismodifiedservice"`
	IsDelays          APIBool `json:"isdelays"`
	CurrentMessage    string  `json:"current_message"`
}

AlertResult is a line returned from the alert API.

func (AlertResult) String added in v1.1.0

func (r AlertResult) String() string

String prints a formatted version of the AlertResult

type Client

type Client struct {

	// Domain is the api domain.
	Domain string

	// Timeout is the number of seconds before the call times out.
	Timeout time.Duration
}

Client is used to make calls to the septa website.

func NewClient

func NewClient(domain string) *Client

NewClient creates a Client with the given domain to make api calls.

func (*Client) Alerts added in v1.1.0

func (c *Client) Alerts(route string) ([]AlertResult, error)

Alerts makes a call to the alerts api and returns the results. If no matching route is found, alerts for all routes will be displayed.

func (*Client) NextToArrive

func (c *Client) NextToArrive(from string, to string, num int) ([]NextToArriveResult, error)

NextToArrive makes a call to the next to arrive api and returns the results

type NextToArriveResult

type NextToArriveResult struct {
	Train           string `json:"orig_train"`
	Line            string `json:"orig_line"`
	DepartureString string `json:"orig_departure_time"`
	ArrivalString   string `json:"orig_arrival_time"`
	Delay           string `json:"orig_delay"`
	IsDirect        string `json:"isdirect"`
}

NextToArriveResult is a line in the NTA response.

func (NextToArriveResult) String

func (r NextToArriveResult) String() string

String returns a formatted string suitable for printing.

type Route added in v1.1.0

type Route struct {
	// ThreeID is a three letter designation for the route
	ThreeID string
	// ID is the API route_id used.
	ID string
	// Name is the route_name used in the API
	Name string
	// Mode is the type of rail, one of Regional Rail, Bus, or there are some other modes.
	Mode string
}

Route is a rail route.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL