goefa

package module
v0.0.0-...-78300a7 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2019 License: AGPL-3.0 Imports: 12 Imported by: 5

README

goEFA

package goefa implements a Go client library to access data of public transport services, which provide an EFA interface. You can search for a stop, query for upcoming departures and request a route / trip itinerary.

goefa

Installation

Make sure you have a working Go environment (Go 1.3 or higher is required). See the install instructions.

To install goEFA, simply run:

go get github.com/muesli/goefa

To compile it from source:

cd $GOPATH/src/github.com/muesli/goefa
go get -u -v
go build && go test -v

Usage

Simple example on how to verify a stop and get the departures:

// create a new EFAProvider
provider := goefa.NewProvider("https://efa.mvv-muenchen.de/mvv/", true)

// Find a stop by name
stops, err := provider.FindStop("Königsplatz")

// Get the 5 next departures for a stop
deps, err := stops[0].Departures(time.Now(), 5)

// Plan a trip between two stops
routes, err := provider.Route(originStop.ID, destinationStop.ID, time.Now())
...

Available Providers

City Provider Base URL
Augsburg AVV https://efa.avv-augsburg.de/avv/
Munich MVV https://efa.mvv-muenchen.de/mvv/

The german wikipedia article on EFA contains more information about EFA and available providers.

GoDoc Build Status Coverage Status Go ReportCard

Documentation

Overview

Package goefa implements a go (golang) client library to access data of public transport companies which provide an EFA interface. You can search a stop, get its next departures or request a trip.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Departure

type Departure struct {
	CountDown    int         // minutes until departure
	MapLink      string      // link to map
	Platform     string      // platform code
	PlatformName string      // platform name
	StopID       int         // ID of the stop
	StopName     string      // name of the stop
	Lat          int64       // Latitude
	Lng          int64       // Longitude
	DateTime     time.Time   // Timestamp of departure
	ServingLine  ServingLine // Line
}

Departure represents a single departure for a specific stop.

type EFATime

type EFATime struct {
	time.Time
}

EFATime implements UnmarshalXML to support unmarshalling EFAs XML DateTime type directly into a time.Time compatible type

func (*EFATime) UnmarshalXML

func (t *EFATime) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML is a custom XML decoding method for EFATime

type MeansOfTransport

type MeansOfTransport struct {
	Name   string `xml:"name,attr"`
	Number string `xml:"symbol,attr"`

	MotType MotType `xml:"motType,attr"`
}

MeansOfTransport represents the Means of Transportation

type MotType

type MotType int

MotType represents the Methods Of Transportation

func (*MotType) String

func (e *MotType) String() string

type Provider

type Provider struct {
	BaseURL        string
	EnableRealtime bool
}

Provider represents a public transport company that provides access to its EFA instance. Use providers.json to store a list of known providers.

func NewProvider

func NewProvider(baseurl string, realtime bool) *Provider

NewProvider returns a new Provider with custom settings

func (*Provider) Departures

func (efa *Provider) Departures(stopID int, due time.Time, results int) ([]*Departure, error)

Departures performs a stateless dm_request for the corresponding stopID and returns an array of Departures. Use time.Now() as the second argument in order to get the very next departures. The third argument determines how many results will be returned by EFA.

func (*Provider) FindStop

func (efa *Provider) FindStop(name string) ([]*Stop, error)

FindStop queries the EFA StopFinder API of the corresponding provider and returns an array of matched stops (or only the identified one) or an error in case somthing went wrong.

func (*Provider) Route

func (efa *Provider) Route(origin int, destination int, due time.Time) ([]*Route, error)

Route requests an itinerary of trips from the stop with ID origin to the stop with ID destination

func (*Provider) Stop

func (efa *Provider) Stop(id int) (*Stop, error)

Stop queries the EFA StopFinder API of the corresponding provider for a stop with a specific ID.

type Response

type Response struct {
	XMLName xml.Name `xml:"itdRequest"`

	Client     string `xml:"client,attr"`
	ClientIP   string `xml:"clientIP,attr"`
	Language   string `xml:"language,attr"`
	LengthUnit string `xml:"lengthUnit,attr"`
	Now        string `xml:"now,attr"`
	NowWD      int    `xml:"nowID,attr"`
	ServerID   string `xml:"serverID,attr"`
	SessionID  int    `xml:"sessionID,attr"`
	Version    string `xml:"version,attr"`
	VirtDir    string `xml:"virtDir,attr"`

	VersionInfo struct {
		AppVersion string `xml:"ptKernel>appVersion"`
		DataFormat string `xml:"ptKernel>dataFormat"`
		DataBuild  string `xml:"ptKernel>dataBuild"`
	} `xml:"itdVersionInfo"`
}

Response is the basic API response for all EFA requests

type Route

type Route struct {
	Trips         []*Trip
	OriginID      int
	DestinationID int
	DepartureTime time.Time
	ArrivalTime   time.Time
}

Route is a route between two stops, including all necessary transfers

type ServingLine

type ServingLine struct {
	// ROP        int    `xml:"ROP,attr"`
	// STT        int    `xml:"displayName,attr"`
	// TTB        int    `xml:"TTB,attr"`
	// Compound   int    `xml:"compound,attr"`
	// Code       int    `xml:"code,attr"`
	// Index      string `xml:"index,attr"`
	Number     string  `xml:"number,attr"`
	Direction  string  `xml:"direction,attr"`
	DestStopID int     `xml:"destID,attr"`
	MotType    MotType `xml:"motType,attr"`
}

ServingLine holds the data for a public transportation line

type Stop

type Stop struct {
	ID             int
	Name           string
	Locality       string
	Lat            float64
	Lng            float64
	IsTransferStop bool

	Provider *Provider
}

Stop represents a public transportation stop

func (*Stop) Departures

func (stop *Stop) Departures(due time.Time, results int) ([]*Departure, error)

Departures is just a helper method and calls the Departures() method of the Provider.

func (*Stop) Route

func (stop *Stop) Route(destination int, due time.Time) ([]*Route, error)

Route is just a helper method and calls the Route() method of the Provider.

type Trip

type Trip struct {
	OriginID            int
	DestinationID       int
	OriginPlatform      string
	DestinationPlatform string
	DepartureTime       time.Time
	ArrivalTime         time.Time
	MeansOfTransport    MeansOfTransport
}

Trip represents a trip from one stop to another

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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