sbb

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2021 License: MIT Imports: 8 Imported by: 0

README

sbb

CLI Timetable queries to the opendata Transport API

Installation

Homebrew
brew install mhutter/tap/sbb
go install
go install github.com/mhutter/sbb/...
Manual installation

You can always download the latest binaries from the releases page.

Usage

$ sbb from Zurich to Brig
---------------------------------------------------------
Zürich HB              dep: 18:02  plat: 31  dur: 02:09
Brig                   arr: 20:11
---------------------------------------------------------
Zürich HB              dep: 19:02  plat: 31  dur: 02:08
Brig                   arr: 21:11
---------------------------------------------------------
Zürich HB              dep: 19:32  plat: 32  dur: 02:09
Brig                   arr: 21:41
---------------------------------------------------------
Zürich HB              dep: 20:32  plat: 32  dur: 02:09
Brig                   arr: 22:41
---------------------------------------------------------
Keywords
Option Description
from Specifies the departure location of the connection
to Specifies the arrival location of the connection
on Date of the connection
at Time of the connection

by @mhutter λ hutter.io λ twitter: @Dratir

Documentation

Index

Constants

View Source
const (
	APIBase = "https://transport.opendata.ch/v1/connections"
)

APIBase Information about the OpenTransport API

Variables

View Source
var RequiredFields = []string{
	"connections/from/station/name",
	"connections/from/departure",
	"connections/from/platform",
	"connections/to/station/name",
	"connections/to/arrival",
	"connections/duration",
}

RequiredFields from the transport APi

Functions

func PrintConnectionList

func PrintConnectionList(connections []Connection)

PrintConnectionList prints out a list of connections

Types

type Checkpoint

type Checkpoint struct {
	Station   Location
	Departure string
	Arrival   string
	Platform  string
}

Checkpoint represents an arrival or a departure point (in time and space) of a connection

type Connection

type Connection struct {
	From     Checkpoint
	To       Checkpoint
	Duration string
}

Connection represents a possible journey between two locations

func (*Connection) DisplayArrival

func (c *Connection) DisplayArrival() string

DisplayArrival returns the formatted starting Location

func (*Connection) DisplayDeparture

func (c *Connection) DisplayDeparture() string

DisplayDeparture returns the formatted starting Location

func (*Connection) DisplayDuration

func (c *Connection) DisplayDuration() string

DisplayDuration returns the formatted starting Location

func (*Connection) DisplayFrom

func (c *Connection) DisplayFrom() string

DisplayFrom returns the formatted starting Location

func (*Connection) DisplayTo

func (c *Connection) DisplayTo() string

DisplayTo returns the formatted starting Location

func (*Connection) Print

func (c *Connection) Print()

Print prints out a single Connection

type Location

type Location struct {
	Name string
}

Location represents a Checkpoint on a Connection

type Query

type Query struct {
	From string
	To   string
	Via  []string
	Time string
	Date string
}

Query represents a timetable enquiry

func ParseQuery

func ParseQuery(in []string) *Query

ParseQuery tries to interpret user input into a query

func (*Query) URL

func (q *Query) URL() string

URL returns the complete url for the open transport API

type Response

type Response struct {
	Connections []Connection
}

Response represents the root object of a OpenTransport API response

func FetchConnections

func FetchConnections(q *Query) (res *Response)

FetchConnections queries the OpenTransport API

Directories

Path Synopsis
cmd
sbb command

Jump to

Keyboard shortcuts

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