tlcsv

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2021 License: GPL-3.0 Imports: 24 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetString

func GetString(ent tl.Entity, key string) (string, error)

GetString convenience method; gets a string representation of a field.

func ReadRows

func ReadRows(in io.Reader, cb func(Row)) error

ReadRows iterates through csv rows with callback.

func SetString

func SetString(ent tl.Entity, key string, value string) error

SetString convenience method; checks for SetString method.

Types

type Adapter

type Adapter interface {
	OpenFile(string, func(io.Reader)) error
	ReadRows(string, func(Row)) error
	Open() error
	Close() error
	Exists() bool
	Path() string
	SHA1() (string, error)
	DirSHA1() (string, error)
}

Adapter provides an interface for working with various kinds of GTFS sources: zip, directory, url.

type DirAdapter

type DirAdapter struct {
	// contains filtered or unexported fields
}

DirAdapter supports plain directories of CSV files.

func NewDirAdapter

func NewDirAdapter(path string) *DirAdapter

NewDirAdapter returns an initialized DirAdapter.

func (*DirAdapter) Close

func (adapter *DirAdapter) Close() error

Close the adapter.

func (*DirAdapter) DirSHA1

func (adapter *DirAdapter) DirSHA1() (string, error)

DirSHA1 returns the SHA1 of all the .txt files in the main directory, sorted, and concatenated.

func (*DirAdapter) Exists

func (adapter *DirAdapter) Exists() bool

Exists checks if the specified directory exists.

func (*DirAdapter) FileInfos

func (adapter *DirAdapter) FileInfos() ([]os.FileInfo, error)

FileInfos returns a list of os.FileInfo for all top-level .txt files.

func (*DirAdapter) Open

func (adapter *DirAdapter) Open() error

Open the adapter. Return an error if the directory does not exist.

func (*DirAdapter) OpenFile

func (adapter *DirAdapter) OpenFile(filename string, cb func(io.Reader)) error

OpenFile opens a file in the directory. Returns an error if the file cannot be read.

func (*DirAdapter) Path

func (adapter *DirAdapter) Path() string

Path returns the directory path.

func (*DirAdapter) ReadRows

func (adapter *DirAdapter) ReadRows(filename string, cb func(Row)) error

ReadRows opens the file and runs the callback for each row. An error is returned if the file cannot be read.

func (*DirAdapter) SHA1

func (adapter *DirAdapter) SHA1() (string, error)

SHA1 returns an error.

func (*DirAdapter) WriteRows

func (adapter *DirAdapter) WriteRows(filename string, rows [][]string) error

WriteRows writes with only Flush at the end.

type OverlayAdapter

type OverlayAdapter struct {
	// contains filtered or unexported fields
}

OverlayAdapter searches a specified list of directories for the specified file. Used for reducing the complexity of writing tests.

func NewOverlayAdapter

func NewOverlayAdapter(paths ...string) OverlayAdapter

NewOverlayAdapter returns a new OverlayAdapter.

func (OverlayAdapter) Close

func (adapter OverlayAdapter) Close() error

Close implements CSV Adapter.Close.

func (OverlayAdapter) DirSHA1

func (adapter OverlayAdapter) DirSHA1() (string, error)

DirSHA1 returns the SHA1 of all the .txt files in the main directory, sorted, and concatenated.

func (OverlayAdapter) Exists

func (adapter OverlayAdapter) Exists() bool

Exists implements CSV Adapter.Exists.

func (OverlayAdapter) Open

func (adapter OverlayAdapter) Open() error

Open implements CSV Adapter Open.

func (OverlayAdapter) OpenFile

func (adapter OverlayAdapter) OpenFile(filename string, cb func(io.Reader)) error

OpenFile searches paths until it finds the specified file.

func (OverlayAdapter) Path

func (adapter OverlayAdapter) Path() string

Path implements CSV Adapter.Path.

func (OverlayAdapter) ReadRows

func (adapter OverlayAdapter) ReadRows(filename string, cb func(Row)) error

ReadRows implements CSV Adapter ReadRows.

func (OverlayAdapter) SHA1

func (adapter OverlayAdapter) SHA1() (string, error)

SHA1 is an alias for DirSHA1

type Reader

type Reader struct {
	Adapter
}

Reader reads GTFS entities from CSV files.

func NewReader

func NewReader(path string) (*Reader, error)

NewReader returns an initialized CSV Reader.

func (*Reader) Agencies

func (reader *Reader) Agencies() (out chan tl.Agency)

Agencies sends Agencies.

func (*Reader) CalendarDates

func (reader *Reader) CalendarDates() (out chan tl.CalendarDate)

CalendarDates sends CalendarDates.

func (*Reader) Calendars

func (reader *Reader) Calendars() (out chan tl.Calendar)

Calendars sends Calendars.

func (*Reader) ContainsFile

func (reader *Reader) ContainsFile(filename string) bool

ContainsFile checks if filename is present and contains a readable row.

func (*Reader) FareAttributes

func (reader *Reader) FareAttributes() (out chan tl.FareAttribute)

FareAttributes sends FareAttributes.

func (*Reader) FareRules

func (reader *Reader) FareRules() (out chan tl.FareRule)

FareRules sends FareRules.

func (*Reader) FeedInfos

func (reader *Reader) FeedInfos() (out chan tl.FeedInfo)

FeedInfos sends FeedInfos.

func (*Reader) Frequencies

func (reader *Reader) Frequencies() (out chan tl.Frequency)

Frequencies sends Frequencies.

func (*Reader) Levels

func (reader *Reader) Levels() (out chan tl.Level)

Levels sends Levels.

func (*Reader) Pathways

func (reader *Reader) Pathways() (out chan tl.Pathway)

Pathways sends Pathways.

func (*Reader) ReadEntities

func (reader *Reader) ReadEntities(c interface{}) error

ReadEntities provides a generic interface for reading entities.

func (*Reader) Routes

func (reader *Reader) Routes() (out chan tl.Route)

Routes sends Routes.

func (*Reader) Shapes

func (reader *Reader) Shapes() chan tl.Shape

Shapes sends single-geometry LineString Shapes

func (*Reader) StopTimes

func (reader *Reader) StopTimes() (out chan tl.StopTime)

StopTimes sends StopTimes.

func (*Reader) StopTimesByTripID

func (reader *Reader) StopTimesByTripID(tripIDs ...string) chan []tl.StopTime

StopTimesByTripID sends StopTimes for selected trips.

func (*Reader) Stops

func (reader *Reader) Stops() (out chan tl.Stop)

Stops sends Stops.

func (*Reader) Transfers

func (reader *Reader) Transfers() (out chan tl.Transfer)

Transfers sends Tranfers.

func (*Reader) Trips

func (reader *Reader) Trips() (out chan tl.Trip)

Trips sends Trips.

func (*Reader) ValidateStructure

func (reader *Reader) ValidateStructure() []error

ValidateStructure returns if all required CSV files are present.

type Row

type Row struct {
	Row    []string
	Header []string
	Hindex map[string]int
	Line   int
	Err    error
}

Row is a row value with a header.

func (*Row) Get

func (row *Row) Get(k string) (string, bool)

Get a value from the row as a string.

type S3Adapter

type S3Adapter struct {
	ZipAdapter
	// contains filtered or unexported fields
}

S3Adapter downloads a GTFS file from an S3 bucket to a temporary file, and removes the file when it is closed.

func (*S3Adapter) Close

func (adapter *S3Adapter) Close() error

Close the adapter, and remove the temporary file. An error is returned if the file could not be deleted.

func (*S3Adapter) Open

func (adapter *S3Adapter) Open() error

Open the adapter, and download the provided URL to a temporary file.

type URLAdapter

type URLAdapter struct {
	ZipAdapter
	// contains filtered or unexported fields
}

URLAdapter downloads a GTFS URL to a temporary file, and removes the file when it is closed.

func (*URLAdapter) Close

func (adapter *URLAdapter) Close() error

Close the adapter, and remove the temporary file. An error is returned if the file could not be deleted.

func (*URLAdapter) Open

func (adapter *URLAdapter) Open() error

Open the adapter, and download the provided URL to a temporary file.

type Writer

type Writer struct {
	WriterAdapter
	// contains filtered or unexported fields
}

Writer implements a GTFS CSV Writer.

func NewWriter

func NewWriter(path string) (*Writer, error)

NewWriter returns a new Writer.

func (*Writer) AddEntities

func (writer *Writer) AddEntities(ents []tl.Entity) ([]string, error)

AddEntities writes entities to the output.

func (*Writer) AddEntity

func (writer *Writer) AddEntity(ent tl.Entity) (string, error)

AddEntity writes an entity to the output.

func (*Writer) Create

func (writer *Writer) Create() error

Create the necessary files for the Writer.

func (*Writer) Delete

func (writer *Writer) Delete() error

Delete the Writer.

func (*Writer) NewReader

func (writer *Writer) NewReader() (tl.Reader, error)

NewReader returns a new Reader for the Writer destination.

type WriterAdapter

type WriterAdapter interface {
	WriteRows(string, [][]string) error
	Adapter
}

WriterAdapter provides a writing interface.

type ZipAdapter

type ZipAdapter struct {
	// contains filtered or unexported fields
}

ZipAdapter supports reading from zip archives.

func NewZipAdapter

func NewZipAdapter(path string) *ZipAdapter

NewZipAdapter returns an initialized zip adapter.

func (ZipAdapter) Close

func (adapter ZipAdapter) Close() error

Close the adapter.

func (ZipAdapter) DirSHA1

func (adapter ZipAdapter) DirSHA1() (string, error)

DirSHA1 returns the SHA1 of all the .txt files in the main directory, sorted, and concatenated.

func (ZipAdapter) Exists

func (adapter ZipAdapter) Exists() bool

Exists returns if the zip file exists.

func (ZipAdapter) FileInfos

func (adapter ZipAdapter) FileInfos() ([]os.FileInfo, error)

FileInfos returns a list of os.FileInfo for all top-level .txt files.

func (ZipAdapter) Open

func (adapter ZipAdapter) Open() error

Open the adapter. Return an error if the file does not exist.

func (ZipAdapter) OpenFile

func (adapter ZipAdapter) OpenFile(filename string, cb func(io.Reader)) error

OpenFile opens the file inside the archive and passes it to the provided callback.

func (ZipAdapter) Path

func (adapter ZipAdapter) Path() string

Path returns the path to the zip file.

func (ZipAdapter) ReadRows

func (adapter ZipAdapter) ReadRows(filename string, cb func(Row)) error

ReadRows opens the specified file and runs the callback on each Row. An error is returned if the file cannot be read.

func (ZipAdapter) SHA1

func (adapter ZipAdapter) SHA1() (string, error)

SHA1 returns the SHA1 checksum of the zip archive.

type ZipWriterAdapter

type ZipWriterAdapter struct {
	DirAdapter
	// contains filtered or unexported fields
}

ZipWriterAdapter functions the same as DirAdapter, but writes to a temporary directory, and creates a zip archive when closed.

func NewZipWriterAdapter

func NewZipWriterAdapter(path string) *ZipWriterAdapter

NewZipWriterAdapter returns a new ZipWriterAdapter.

func (*ZipWriterAdapter) Close

func (adapter *ZipWriterAdapter) Close() error

Close creates a zip archive of all the written files at the specified destination.

Jump to

Keyboard shortcuts

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