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
|
import logging
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from threading import Lock
|
from threading import Lock
|
||||||
from typing import Any, Optional
|
from typing import Optional
|
||||||
|
|
||||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||||
from webdav3.client import Client, Resource
|
from webdav3.client import Resource
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -13,8 +13,8 @@ class DavFile:
|
||||||
__instances: Optional[list["DavFile"]] = None
|
__instances: Optional[list["DavFile"]] = None
|
||||||
__scheduler = None
|
__scheduler = None
|
||||||
|
|
||||||
def __init__(self, client: Client, path: Any) -> None:
|
def __init__(self, resource: Resource, refresh: bool = True) -> None:
|
||||||
self.__resource: Resource = client.resource(path)
|
self.__resource: Resource = resource
|
||||||
self.__buffer = BytesIO()
|
self.__buffer = BytesIO()
|
||||||
self.__lock = Lock()
|
self.__lock = Lock()
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ class DavFile:
|
||||||
if DavFile.__instances is None:
|
if DavFile.__instances is None:
|
||||||
DavFile.__instances = []
|
DavFile.__instances = []
|
||||||
|
|
||||||
|
if refresh:
|
||||||
DavFile.__instances.append(self)
|
DavFile.__instances.append(self)
|
||||||
|
|
||||||
def download(self) -> None:
|
def download(self) -> None:
|
||||||
|
|
|
@ -24,9 +24,9 @@ _title = ""
|
||||||
async def on_startup():
|
async def on_startup():
|
||||||
global _message, _ticker, _title
|
global _message, _ticker, _title
|
||||||
|
|
||||||
_message = DavFile(client=CLIENT, path="message.txt")
|
_message = DavFile(CLIENT.resource("message.txt"))
|
||||||
_ticker = DavFile(client=CLIENT, path="ticker.txt")
|
_ticker = DavFile(CLIENT.resource("ticker.txt"))
|
||||||
_title = DavFile(client=CLIENT, path="title.txt")
|
_title = DavFile(CLIENT.resource("title.txt"))
|
||||||
DavFile.refresh(60)
|
DavFile.refresh(60)
|
||||||
|
|
||||||
_logger.debug("text router started")
|
_logger.debug("text router started")
|
||||||
|
|
Loading…
Reference in a new issue