From df7b0310246fd6a9425ef355cc73185fefeb77ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Mon, 29 Aug 2022 19:20:03 +0000 Subject: [PATCH] ticker content + markdown --- api/ovkiosk/config.py | 2 ++ api/ovkiosk/routers/text.py | 26 +++++++++++++---- api/poetry.lock | 56 ++++++++++++++++++++++++++++++++++++- api/pyproject.toml | 1 + 4 files changed, 78 insertions(+), 7 deletions(-) diff --git a/api/ovkiosk/config.py b/api/ovkiosk/config.py index 0a641e6..8486996 100644 --- a/api/ovkiosk/config.py +++ b/api/ovkiosk/config.py @@ -31,6 +31,8 @@ class Settings(BaseSettings): dav_password: str = "changeme" dav_path: str = "ovkiosk" + ticker_separator: str = " +++ " + @property def caldav_url(self) -> str: return f"{self.dav_protocol}://" + \ diff --git a/api/ovkiosk/routers/text.py b/api/ovkiosk/routers/text.py index 1f3d3f5..93210ba 100644 --- a/api/ovkiosk/routers/text.py +++ b/api/ovkiosk/routers/text.py @@ -1,13 +1,15 @@ import logging from fastapi import APIRouter +from markdown import Markdown -from .. import CLIENT +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") @@ -25,14 +27,26 @@ async def on_startup(): @router.get("/message") async def get_message(): - return str(_message) + return _md.convert( + str(_message) + ) -@router.get("/ticker") -async def get_ticker(): - return str(_ticker) +@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 str(_title) + return _md.convert( + str(_title) + ) diff --git a/api/poetry.lock b/api/poetry.lock index f800d7d..69fe29d 100644 --- a/api/poetry.lock +++ b/api/poetry.lock @@ -87,6 +87,22 @@ category = "main" optional = false python-versions = ">=3.5" +[[package]] +name = "importlib-metadata" +version = "4.12.0" +description = "Read metadata from Python packages" +category = "main" +optional = false +python-versions = ">=3.7" + +[package.dependencies] +zipp = ">=0.5" + +[package.extras] +docs = ["jaraco.packaging (>=9)", "rst.linker (>=1.9)", "sphinx"] +perf = ["ipython"] +testing = ["flufl.flake8", "importlib-resources (>=1.3)", "packaging", "pyfakefs", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.3)", "pytest-flake8", "pytest-mypy (>=0.9.1)", "pytest-perf (>=0.9.2)"] + [[package]] name = "lxml" version = "4.9.1" @@ -101,6 +117,20 @@ html5 = ["html5lib"] htmlsoup = ["beautifulsoup4"] source = ["Cython (>=0.29.7)"] +[[package]] +name = "markdown" +version = "3.4.1" +description = "Python implementation of Markdown." +category = "main" +optional = false +python-versions = ">=3.7" + +[package.dependencies] +importlib-metadata = {version = ">=4.4", markers = "python_version < \"3.10\""} + +[package.extras] +testing = ["coverage", "pyyaml"] + [[package]] name = "pydantic" version = "1.9.2" @@ -237,10 +267,22 @@ lxml = "*" python-dateutil = "*" requests = "*" +[[package]] +name = "zipp" +version = "3.8.1" +description = "Backport of pathlib-compatible object wrapper for zip files" +category = "main" +optional = false +python-versions = ">=3.7" + +[package.extras] +docs = ["jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx"] +testing = ["func-timeout", "jaraco.itertools", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.3)", "pytest-flake8", "pytest-mypy (>=0.9.1)"] + [metadata] lock-version = "1.1" python-versions = "^3.9" -content-hash = "7e0eb7ac07e275ac9e89d8f7b5fac4a2320c9e8756b7f050e64891bbae0074c1" +content-hash = "a8edb56f5824246d8a490c280bf11318d1efa11d6109b4982b8adf15b391d587" [metadata.files] anyio = [ @@ -275,6 +317,10 @@ idna = [ {file = "idna-3.3-py3-none-any.whl", hash = "sha256:84d9dd047ffa80596e0f246e2eab0b391788b0503584e8945f2368256d2735ff"}, {file = "idna-3.3.tar.gz", hash = "sha256:9d643ff0a55b762d5cdb124b8eaa99c66322e2157b69160bc32796e824360e6d"}, ] +importlib-metadata = [ + {file = "importlib_metadata-4.12.0-py3-none-any.whl", hash = "sha256:7401a975809ea1fdc658c3aa4f78cc2195a0e019c5cbc4c06122884e9ae80c23"}, + {file = "importlib_metadata-4.12.0.tar.gz", hash = "sha256:637245b8bab2b6502fcbc752cc4b7a6f6243bb02b31c5c26156ad103d3d45670"}, +] lxml = [ {file = "lxml-4.9.1-cp27-cp27m-macosx_10_15_x86_64.whl", hash = "sha256:98cafc618614d72b02185ac583c6f7796202062c41d2eeecdf07820bad3295ed"}, {file = "lxml-4.9.1-cp27-cp27m-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:c62e8dd9754b7debda0c5ba59d34509c4688f853588d75b53c3791983faa96fc"}, @@ -347,6 +393,10 @@ lxml = [ {file = "lxml-4.9.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl", hash = "sha256:287605bede6bd36e930577c5925fcea17cb30453d96a7b4c63c14a257118dbb9"}, {file = "lxml-4.9.1.tar.gz", hash = "sha256:fe749b052bb7233fe5d072fcb549221a8cb1a16725c47c37e42b0b9cb3ff2c3f"}, ] +markdown = [ + {file = "Markdown-3.4.1-py3-none-any.whl", hash = "sha256:08fb8465cffd03d10b9dd34a5c3fea908e20391a2a90b88d66362cb05beed186"}, + {file = "Markdown-3.4.1.tar.gz", hash = "sha256:3b809086bb6efad416156e00a0da66fe47618a5d6918dd688f53f40c8e4cfeff"}, +] pydantic = [ {file = "pydantic-1.9.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:9c9e04a6cdb7a363d7cb3ccf0efea51e0abb48e180c0d31dca8d247967d85c6e"}, {file = "pydantic-1.9.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:fafe841be1103f340a24977f61dee76172e4ae5f647ab9e7fd1e1fca51524f08"}, @@ -423,3 +473,7 @@ uvicorn = [ webdavclient3 = [ {file = "webdavclient3-3.14.5.tar.gz", hash = "sha256:6072f9a583059f8ff313f8544d415b4191fc89bdf6230259b0527b706ab1837b"}, ] +zipp = [ + {file = "zipp-3.8.1-py3-none-any.whl", hash = "sha256:47c40d7fe183a6f21403a199b3e4192cca5774656965b0a4988ad2f8feb5f009"}, + {file = "zipp-3.8.1.tar.gz", hash = "sha256:05b45f1ee8f807d0cc928485ca40a07cb491cf092ff587c0df9cb1fd154848d2"}, +] diff --git a/api/pyproject.toml b/api/pyproject.toml index cf79ad4..d58b7ff 100644 --- a/api/pyproject.toml +++ b/api/pyproject.toml @@ -10,6 +10,7 @@ pydantic = {extras = ["dotenv"], version = "^1.9.2"} python = "^3.9" uvicorn = "^0.18.3" webdavclient3 = "3.14.5" +Markdown = "^3.4.1" [tool.poetry.dev-dependencies] # pytest = "^5.2"