split TickerConfig

This commit is contained in:
Jörn-Michael Miehe 2022-09-08 23:59:17 +00:00
parent 83db799b96
commit ccbac0a455
2 changed files with 24 additions and 7 deletions

View file

@ -18,18 +18,35 @@ from .settings import SETTINGS
_logger = getLogger(__name__) _logger = getLogger(__name__)
class TickerConfig(BaseModel): class TickerAPIConfig(BaseModel):
""" """
Section "[ticker]" in "config.txt". Section "[ticker.api]" in "config.txt".
""" """
file_name: str = "ticker" file_name: str = "ticker"
separator: str = " +++ " separator: str = " +++ "
comment_marker: str = "#" comment_marker: str = "#"
class TickerUIConfig(BaseModel):
"""
Section "[ticker.ui]" in "config.txt".
"""
display: bool = True
color: str = "primary" color: str = "primary"
speed: int = 30 speed: int = 30
class TickerConfig(BaseModel):
"""
Section "[ticker]" in "config.txt".
"""
api: TickerAPIConfig = TickerAPIConfig()
ui: TickerUIConfig = TickerUIConfig()
class ImageConfig(BaseModel): class ImageConfig(BaseModel):
""" """
Sections "[image*]" in "config.txt". Sections "[image*]" in "config.txt".
@ -72,7 +89,7 @@ class Config(BaseModel):
dav_file = DavFile(SETTINGS.config_path) dav_file = DavFile(SETTINGS.config_path)
try: try:
return cls.parse_obj( cfg = cls.parse_obj(
toml_loads(await dav_file.as_string) toml_loads(await dav_file.as_string)
) )

View file

@ -34,7 +34,7 @@ async def start_router() -> None:
async def get_ticker_lines() -> Iterator[str]: async def get_ticker_lines() -> Iterator[str]:
cfg = await Config.get() cfg = await Config.get()
file_name = await text_unique(cfg.ticker.file_name) file_name = await text_unique(cfg.ticker.api.file_name)
ticker = await DavFile( ticker = await DavFile(
f"{await text_lister.remote_path}/{file_name}", f"{await text_lister.remote_path}/{file_name}",
@ -55,7 +55,7 @@ async def get_ticker_content_lines(
return ( return (
line line
for line in ticker_lines for line in ticker_lines
if not line.startswith(cfg.ticker.comment_marker) if not line.startswith(cfg.ticker.api.comment_marker)
) )
@ -63,7 +63,7 @@ async def get_ticker_content(
ticker_content_lines: Iterator[str] = Depends(get_ticker_content_lines), ticker_content_lines: Iterator[str] = Depends(get_ticker_content_lines),
) -> str: ) -> str:
cfg = await Config.get() cfg = await Config.get()
ticker_content = cfg.ticker.separator.join( ticker_content = cfg.ticker.api.separator.join(
["", *ticker_content_lines, ""], ["", *ticker_content_lines, ""],
) )