refactor DavFile init
This commit is contained in:
parent
6859e29986
commit
cfb813f787
2 changed files with 9 additions and 8 deletions
|
@ -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,6 +22,7 @@ class DavFile:
|
|||
if DavFile.__instances is None:
|
||||
DavFile.__instances = []
|
||||
|
||||
if refresh:
|
||||
DavFile.__instances.append(self)
|
||||
|
||||
def download(self) -> None:
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue