ovdashboard/api/ovkiosk/routers/text.py

53 lines
1 KiB
Python
Raw Normal View History

2022-08-29 11:27:18 +00:00
import logging
from fastapi import APIRouter
2022-08-29 19:20:03 +00:00
from markdown import Markdown
2022-08-29 11:27:18 +00:00
2022-08-29 19:20:03 +00:00
from .. import CLIENT, SETTINGS
2022-08-29 11:27:18 +00:00
from ..dav_file import DavFile
router = APIRouter(prefix="/text", tags=["text"])
_logger = logging.getLogger(__name__)
2022-08-29 19:20:03 +00:00
_md = Markdown()
2022-08-29 11:27:18 +00:00
_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():
2022-08-29 19:20:03 +00:00
return _md.convert(
str(_message)
)
2022-08-29 11:27:18 +00:00
2022-08-29 19:20:03 +00:00
@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)
)
2022-08-29 11:27:18 +00:00
@router.get("/title")
async def get_title():
2022-08-29 19:20:03 +00:00
return _md.convert(
str(_title)
)