rechu.io package

Submodules

rechu.io.base module

Abstract base classes for file reading, writing and parsing.

class rechu.io.base.Reader(path: Path, updated: datetime = datetime.datetime(1, 1, 1, 0, 0))[source]

Bases: Generic[T]

File reader.

parse(file: IO) Iterator[T][source]

Parse an open file and yield specific models from it.

property path: Path

Retrieve the path from which to read the models.

read() Iterator[T][source]

Read the file from the path and yield specific models from it.

class rechu.io.base.Writer(path: Path, models: Collection[T], updated: datetime | None = None)[source]

Bases: Generic[T]

File writer.

property path: Path

Retrieve the path to which to write the models.

serialize(file: IO) None[source]

Write a serialized variant of the models to the open file.

write() None[source]

Write the models to the path.

class rechu.io.base.YAMLReader(path: Path, updated: datetime = datetime.datetime(1, 1, 1, 0, 0))[source]

Bases: Reader[T]

YAML file reader.

load(file: IO) Any[source]

Load the YAML file as a Python value.

class rechu.io.base.YAMLWriter(path: Path, models: Collection[T], updated: datetime | None = None)[source]

Bases: Writer[T]

YAML file writer.

TAG_FLOAT = 'tag:yaml.org,2002:float'
TAG_INT = 'tag:yaml.org,2002:int'
TAG_STR = 'tag:yaml.org,2002:str'
save(data: Any, file: IO) None[source]

Save the YAML file from a Python value.

rechu.io.products module

Products matching metadata file handling.

class rechu.io.products.ProductsReader(path: Path, updated: datetime = datetime.datetime(1, 1, 1, 0, 0))[source]

Bases: YAMLReader[Product]

File reader for products metadata.

parse(file: IO) Iterator[Product][source]

Parse an open file and yield specific models from it.

class rechu.io.products.ProductsWriter(path: Path, models: Collection[Product], updated: datetime | None = None, shared_fields: tuple[str, ...] = ('shop', 'category', 'type'))[source]

Bases: YAMLWriter[Product]

File writer for products metadata.

serialize(file: IO) None[source]

Write a serialized variant of the models to the open file.

rechu.io.receipt module

Receipt file handling.

class rechu.io.receipt.ReceiptReader(path: Path, updated: datetime = datetime.datetime(1, 1, 1, 0, 0))[source]

Bases: YAMLReader[Receipt]

Receipt file reader.

parse(file: IO) Iterator[Receipt][source]

Parse an open file and yield specific models from it.

class rechu.io.receipt.ReceiptWriter(path: Path, models: Collection[Receipt], updated: datetime | None = None)[source]

Bases: YAMLWriter[Receipt]

Receipt file writer.

serialize(file: IO) None[source]

Write a serialized variant of the models to the open file.

Module contents

Models for file reading and writing.

class rechu.io.ReceiptReader(path: Path, updated: datetime = datetime.datetime(1, 1, 1, 0, 0))[source]

Bases: YAMLReader[Receipt]

Receipt file reader.

parse(file: IO) Iterator[Receipt][source]

Parse an open file and yield specific models from it.