import logging from fastapi import APIRouter from markdown import Markdown from .. import CLIENT, SETTINGS from ..dav_file import DavFile router = APIRouter(prefix="/text", tags=["text"]) _logger = logging.getLogger(__name__) _md = Markdown() _message = DavFile(client=CLIENT, path="message.txt") _ticker = DavFile(client=CLIENT, path="ticker.txt") _title = DavFile(client=CLIENT, path="title.txt") @router.on_event("startup") async def on_startup(): _logger.debug("text router startup") _message.refresh() _ticker.refresh() _title.refresh() @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) )