split TickerConfig
This commit is contained in:
parent
83db799b96
commit
ccbac0a455
2 changed files with 24 additions and 7 deletions
|
@ -18,18 +18,35 @@ from .settings import SETTINGS
|
|||
_logger = getLogger(__name__)
|
||||
|
||||
|
||||
class TickerConfig(BaseModel):
|
||||
class TickerAPIConfig(BaseModel):
|
||||
"""
|
||||
Section "[ticker]" in "config.txt".
|
||||
Section "[ticker.api]" in "config.txt".
|
||||
"""
|
||||
|
||||
file_name: str = "ticker"
|
||||
separator: str = " +++ "
|
||||
comment_marker: str = "#"
|
||||
|
||||
|
||||
class TickerUIConfig(BaseModel):
|
||||
"""
|
||||
Section "[ticker.ui]" in "config.txt".
|
||||
"""
|
||||
|
||||
display: bool = True
|
||||
color: str = "primary"
|
||||
speed: int = 30
|
||||
|
||||
|
||||
class TickerConfig(BaseModel):
|
||||
"""
|
||||
Section "[ticker]" in "config.txt".
|
||||
"""
|
||||
|
||||
api: TickerAPIConfig = TickerAPIConfig()
|
||||
ui: TickerUIConfig = TickerUIConfig()
|
||||
|
||||
|
||||
class ImageConfig(BaseModel):
|
||||
"""
|
||||
Sections "[image*]" in "config.txt".
|
||||
|
@ -72,7 +89,7 @@ class Config(BaseModel):
|
|||
dav_file = DavFile(SETTINGS.config_path)
|
||||
|
||||
try:
|
||||
return cls.parse_obj(
|
||||
cfg = cls.parse_obj(
|
||||
toml_loads(await dav_file.as_string)
|
||||
)
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ async def start_router() -> None:
|
|||
|
||||
async def get_ticker_lines() -> Iterator[str]:
|
||||
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(
|
||||
f"{await text_lister.remote_path}/{file_name}",
|
||||
|
@ -55,7 +55,7 @@ async def get_ticker_content_lines(
|
|||
return (
|
||||
line
|
||||
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),
|
||||
) -> str:
|
||||
cfg = await Config.get()
|
||||
ticker_content = cfg.ticker.separator.join(
|
||||
ticker_content = cfg.ticker.api.separator.join(
|
||||
["", *ticker_content_lines, ""],
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue