modular parser framework
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
"""Registry for city/source parser implementations."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from openmensa_parsers.parsers.base import OpenMensaParser
|
||||
from openmensa_parsers.parsers.potsdam import PotsdamParser
|
||||
|
||||
|
||||
PARSER_CLASSES: dict[str, type[OpenMensaParser]] = {
|
||||
PotsdamParser.id: PotsdamParser,
|
||||
}
|
||||
|
||||
|
||||
def get_parser_class(parser_id: str) -> type[OpenMensaParser]:
|
||||
try:
|
||||
return PARSER_CLASSES[parser_id]
|
||||
except KeyError as exc:
|
||||
configured = ", ".join(sorted(PARSER_CLASSES))
|
||||
raise KeyError(
|
||||
f"Unknown parser {parser_id!r}; configured parsers: {configured}"
|
||||
) from exc
|
||||
|
||||
|
||||
def create_parser(parser_id: str) -> OpenMensaParser:
|
||||
return get_parser_class(parser_id)()
|
||||
Reference in New Issue
Block a user