ovdashboard/api/ovkiosk/routers/text.py

56 lines
1.1 KiB
Python

import logging
from fastapi import APIRouter
from markdown import Markdown
from .. import CLIENT
from ..config import SETTINGS
from ..dav_file import DavFile
router = APIRouter(prefix="/text", tags=["text"])
_logger = logging.getLogger(__name__)
_md = Markdown()
_message = ""
_ticker = ""
_title = ""
@router.on_event("startup")
async def on_startup():
global _message, _ticker, _title
_message = DavFile(client=CLIENT, path="message.txt")
_ticker = DavFile(client=CLIENT, path="ticker.txt")
_title = DavFile(client=CLIENT, path="title.txt")
DavFile.refresh(60)
_logger.debug("text router started")
@router.get("/message")
async def get_message():
return _md.convert(
str(_message)
)
@router.get("/ticker/content")
async def get_ticker_content():
ticker_clean = (
line.strip()
for line in str(_ticker).split("\n")
if line and not line.startswith(".")
)
return _md.convert(
SETTINGS.ticker_separator.join(ticker_clean)
)
@router.get("/title")
async def get_title():
return _md.convert(
str(_title)
)