diff --git a/api/advent22_api/dav_common.py b/api/advent22_api/dav_common.py index b01d898..ab602d6 100644 --- a/api/advent22_api/dav_common.py +++ b/api/advent22_api/dav_common.py @@ -1,5 +1,6 @@ import re -from io import BytesIO +from io import BytesIO, TextIOWrapper +from typing import TextIO from webdav3.client import Client as WebDAVclient @@ -29,3 +30,8 @@ async def dav_get_file(path: str) -> BytesIO: buffer.seek(0) return buffer + + +async def dav_get_textfile(path: str, encoding="utf-8") -> TextIO: + buffer = await dav_get_file(path) + return TextIOWrapper(buffer, encoding=encoding) diff --git a/api/advent22_api/routers/_misc.py b/api/advent22_api/routers/_misc.py index 3947a13..f1c98de 100644 --- a/api/advent22_api/routers/_misc.py +++ b/api/advent22_api/routers/_misc.py @@ -2,12 +2,12 @@ import itertools import random from typing import Any, Sequence -from ..dav_common import dav_get_file +from ..dav_common import dav_get_textfile async def get_loesungswort() -> str: - fp = await dav_get_file("loesungswort.txt") - return fp.read().decode("utf8").strip() + fp = await dav_get_textfile("loesungswort.txt") + return fp.read().strip() async def get_rnd(bonus_salt: Any = "") -> random.Random: