tlcsv

package
v0.16.2 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: GPL-3.0 Imports: 24 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

Functions

func GetString

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

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

func ReadEntities added in v0.11.0

func ReadEntities[T any](reader *Reader, efn string) chan T

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)
	String() string
}

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

func NewAdapter added in v0.10.1

func NewAdapter(address string) (Adapter, error)

NewAdapter returns a basic adapter for the given URL. Use NewURLAdapter() to provide additional options.

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) AddFile added in v0.8.5

func (adapter *DirAdapter) AddFile(filename string, reader io.Reader) error

AddFile directly adds a file to this directory. Useful for manual feed operations.

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) String added in v0.11.0

func (adapter *DirAdapter) String() string

String

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) CreateZip added in v0.8.5

func (adapter OverlayAdapter) CreateZip(outfile string) error

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) Files added in v0.8.5

func (adapter OverlayAdapter) Files() ([]string, error)

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

func (OverlayAdapter) String added in v0.11.0

func (adapter OverlayAdapter) String() string

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 NewReaderFromAdapter added in v0.10.1

func NewReaderFromAdapter(a Adapter) (*Reader, error)

func (*Reader) Agencies

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

func (*Reader) Areas added in v0.11.0

func (reader *Reader) Areas() (out chan tl.Area)

func (*Reader) Attributions added in v0.10.0

func (reader *Reader) Attributions() (out chan tl.Attribution)

func (*Reader) CalendarDates

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

func (*Reader) Calendars

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

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)

func (*Reader) FareLegRules added in v0.11.0

func (reader *Reader) FareLegRules() (out chan tl.FareLegRule)

func (*Reader) FareMedia added in v0.13.0

func (reader *Reader) FareMedia() (out chan tl.FareMedia)

func (*Reader) FareProducts added in v0.11.0

func (reader *Reader) FareProducts() (out chan tl.FareProduct)

func (*Reader) FareRules

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

func (*Reader) FareTransferRules added in v0.11.0

func (reader *Reader) FareTransferRules() (out chan tl.FareTransferRule)

func (*Reader) FeedInfos

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

func (*Reader) Frequencies

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

func (*Reader) Levels

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

func (*Reader) Pathways

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

func (*Reader) ReadEntities

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

ReadEntities provides a generic interface for reading entities.

func (*Reader) RiderCategories added in v0.11.0

func (reader *Reader) RiderCategories() (out chan tl.RiderCategory)

func (*Reader) Routes

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

func (*Reader) Shapes

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

Shapes sends single-geometry LineString Shapes

func (*Reader) StopAreas added in v0.11.0

func (reader *Reader) StopAreas() (out chan tl.StopArea)

func (*Reader) StopTimes

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

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)

func (*Reader) String added in v0.10.1

func (reader *Reader) String() string

func (*Reader) Transfers

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

func (*Reader) Translations added in v0.10.0

func (reader *Reader) Translations() (out chan tl.Translation)

func (*Reader) Trips

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

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 TmpZipAdapter added in v0.12.0

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

TmpZipAdapter is similar to ZipAdapter, but deletes the file on close.

func NewTmpZipAdapterFromReader added in v0.12.0

func NewTmpZipAdapterFromReader(reader io.Reader, fragment string) (*TmpZipAdapter, error)

func (*TmpZipAdapter) Close added in v0.12.0

func (adapter *TmpZipAdapter) Close() error

func (*TmpZipAdapter) Open added in v0.12.0

func (adapter *TmpZipAdapter) Open() error

type URLAdapter

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

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

func NewURLAdapter added in v0.10.1

func NewURLAdapter(address string, opts ...request.RequestOption) *URLAdapter

func (*URLAdapter) Open

func (adapter *URLAdapter) Open() error

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

func (*URLAdapter) String added in v0.11.0

func (adapter *URLAdapter) String() string

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.

func (*Writer) String added in v0.10.1

func (writer *Writer) String() string

func (*Writer) WriteExtraColumns added in v0.11.0

func (writer *Writer) WriteExtraColumns(val bool)

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 .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.

func (*ZipAdapter) String added in v0.11.0

func (adapter *ZipAdapter) String() string

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