sbb

package module
v1.1.1 Latest Latest
Warning

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

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

README

sbb

CLI Timetable queries to the opendata Transport API

Installation

go install github.com/mhutter/sbb/...

Usage

$ sbb from Zurich to Brig
---------------------------------------------------------
Zürich HB                      dep: 06:02     dur: 02:09
Brig                           arr: 08:11
---------------------------------------------------------
Zürich HB                      dep: 06:32     dur: 02:08
Brig                           arr: 08:40
---------------------------------------------------------
Zürich HB                      dep: 07:02     dur: 02:09
Brig                           arr: 09:11
---------------------------------------------------------
Zürich HB                      dep: 08:02     dur: 02:09
Brig                           arr: 10:11
---------------------------------------------------------
Keywords
Option Description
from Specifies the departure location of the connection
to Specifies the arrival location of the connection
date Date of the connection
time 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/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
}

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