diff --git a/api/ovkiosk/dav_file.py b/api/ovkiosk/dav_file.py index 1d690d4..1e80c2e 100644 --- a/api/ovkiosk/dav_file.py +++ b/api/ovkiosk/dav_file.py @@ -1,10 +1,10 @@ import logging from io import BytesIO from threading import Lock -from typing import Any, Optional +from typing import Optional from apscheduler.schedulers.asyncio import AsyncIOScheduler -from webdav3.client import Client, Resource +from webdav3.client import Resource _logger = logging.getLogger(__name__) @@ -13,8 +13,8 @@ class DavFile: __instances: Optional[list["DavFile"]] = None __scheduler = None - def __init__(self, client: Client, path: Any) -> None: - self.__resource: Resource = client.resource(path) + def __init__(self, resource: Resource, refresh: bool = True) -> None: + self.__resource: Resource = resource self.__buffer = BytesIO() self.__lock = Lock() @@ -22,7 +22,8 @@ class DavFile: if DavFile.__instances is None: DavFile.__instances = [] - DavFile.__instances.append(self) + if refresh: + DavFile.__instances.append(self) def download(self) -> None: _logger.info(f"updating {self.__resource}") diff --git a/api/ovkiosk/routers/text.py b/api/ovkiosk/routers/text.py index 1f308f6..352df64 100644 --- a/api/ovkiosk/routers/text.py +++ b/api/ovkiosk/routers/text.py @@ -24,9 +24,9 @@ _title = "" 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") + _message = DavFile(CLIENT.resource("message.txt")) + _ticker = DavFile(CLIENT.resource("ticker.txt")) + _title = DavFile(CLIENT.resource("title.txt")) DavFile.refresh(60) _logger.debug("text router started")