From 5cf0846c6814e41d8d7bccef871f7c5435071c66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Fri, 8 Sep 2023 01:19:15 +0000 Subject: [PATCH] basic readability --- api/advent22_api/dav_common.py | 2 +- api/advent22_api/routers/_misc.py | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/api/advent22_api/dav_common.py b/api/advent22_api/dav_common.py index 264182a..6f6e3c2 100644 --- a/api/advent22_api/dav_common.py +++ b/api/advent22_api/dav_common.py @@ -17,7 +17,7 @@ _WEBDAV_CLIENT = WebDAVclient( @AsyncTTL(time_to_live=SETTINGS.cache_ttl) -async def dav_list_files(regex: re.Pattern, directory: str = "") -> list[str]: +async def dav_list_files(regex: re.Pattern[str], directory: str = "") -> list[str]: ls = _WEBDAV_CLIENT.list(directory) return [f"{directory}/{path}" for path in ls if regex.search(path)] diff --git a/api/advent22_api/routers/_misc.py b/api/advent22_api/routers/_misc.py index ec44dd2..899bf88 100644 --- a/api/advent22_api/routers/_misc.py +++ b/api/advent22_api/routers/_misc.py @@ -51,17 +51,15 @@ async def get_letter( return (await shuffle(cfg.puzzle.solution))[index] -_RE_IMAGE_FILE = re.compile( - r"\.(gif|jpe?g|tiff?|png|bmp)$", - flags=re.IGNORECASE, -) - - async def list_images_auto() -> list[str]: """ Finde alle Bilder im "automatisch"-Verzeichnis """ - ls = await dav_list_files(_RE_IMAGE_FILE, "/images_auto") + + ls = await dav_list_files( + re.compile(r"\.(gif|jpe?g|tiff?|png|bmp)$", flags=re.IGNORECASE), + "/images_auto", + ) ls = await set_length(ls, 24) return await shuffle(ls)