refac: get_all_image_names using new helper list_images_manual
This commit is contained in:
parent
367fef145d
commit
2a9635c8c1
3 changed files with 27 additions and 13 deletions
2
Ideen.md
2
Ideen.md
|
@ -10,8 +10,6 @@
|
||||||
## Penner
|
## Penner
|
||||||
|
|
||||||
- immer TODOs finden: Ctrl-Shift-F "penner"
|
- immer TODOs finden: Ctrl-Shift-F "penner"
|
||||||
- API: Werte aus `config.py` an sinnvollen Stellen benutzen
|
|
||||||
- API: `depends.py:get_all_image_names` (ab Z. 86) manuelle Bilder einpflegen
|
|
||||||
|
|
||||||
# Erledigt
|
# Erledigt
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,14 @@ from .advent_image import _XY, AdventImage
|
||||||
from .calendar_config import CalendarConfig, get_calendar_config
|
from .calendar_config import CalendarConfig, get_calendar_config
|
||||||
from .config import Config, get_config
|
from .config import Config, get_config
|
||||||
from .dav.webdav import WebDAV
|
from .dav.webdav import WebDAV
|
||||||
from .helpers import EventDates, Random, list_images_auto, load_image, set_len
|
from .helpers import (
|
||||||
|
EventDates,
|
||||||
|
Random,
|
||||||
|
list_images_auto,
|
||||||
|
list_images_manual,
|
||||||
|
load_image,
|
||||||
|
set_len,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def get_all_sorted_days(
|
async def get_all_sorted_days(
|
||||||
|
@ -87,19 +94,17 @@ async def get_all_auto_image_names(
|
||||||
|
|
||||||
async def get_all_image_names(
|
async def get_all_image_names(
|
||||||
auto_image_names: dict[int, str] = Depends(get_all_auto_image_names),
|
auto_image_names: dict[int, str] = Depends(get_all_auto_image_names),
|
||||||
|
manual_image_names: list[str] = Depends(list_images_manual),
|
||||||
) -> dict[int, str]:
|
) -> dict[int, str]:
|
||||||
"""
|
"""
|
||||||
Bilder "auto" und "manual" zu Tagen zuordnen
|
Bilder "auto" und "manual" zu Tagen zuordnen
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__DIR = "/images_manual"
|
num_re = re.compile(r"/(\d+)\.", flags=re.IGNORECASE)
|
||||||
__RE = re.compile(r"\.jpg$", flags=re.IGNORECASE)
|
|
||||||
|
|
||||||
manual_image_names = await WebDAV.list_files(directory=__DIR, regex=__RE)
|
|
||||||
|
|
||||||
for name in manual_image_names:
|
for name in manual_image_names:
|
||||||
zahl = int(__RE.sub(string=name, repl=""))
|
assert (num_match := num_re.search(name)) is not None
|
||||||
auto_image_names[zahl] = f"{__DIR}/{name}"
|
auto_image_names[int(num_match.group(1))] = name
|
||||||
|
|
||||||
return auto_image_names
|
return auto_image_names
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ from .config import get_config
|
||||||
from .dav.webdav import WebDAV
|
from .dav.webdav import WebDAV
|
||||||
|
|
||||||
T = TypeVar("T")
|
T = TypeVar("T")
|
||||||
|
RE_IMG = re.compile(r"\.(gif|jpe?g|tiff?|png|bmp)$", flags=re.IGNORECASE)
|
||||||
|
|
||||||
|
|
||||||
class Random(random.Random):
|
class Random(random.Random):
|
||||||
|
@ -88,10 +89,20 @@ async def list_images_auto() -> list[str]:
|
||||||
|
|
||||||
return [
|
return [
|
||||||
f"{__DIR}/{file}"
|
f"{__DIR}/{file}"
|
||||||
for file in await WebDAV.list_files(
|
for file in await WebDAV.list_files(directory=__DIR, regex=RE_IMG)
|
||||||
directory=__DIR,
|
]
|
||||||
regex=re.compile(r"\.(gif|jpe?g|tiff?|png|bmp)$", flags=re.IGNORECASE),
|
|
||||||
)
|
|
||||||
|
async def list_images_manual() -> list[str]:
|
||||||
|
"""
|
||||||
|
Finde alle Bilddateien im "manuell"-Verzeichnis
|
||||||
|
"""
|
||||||
|
|
||||||
|
__DIR = "/images_manual"
|
||||||
|
|
||||||
|
return [
|
||||||
|
f"{__DIR}/{file}"
|
||||||
|
for file in await WebDAV.list_files(directory=__DIR, regex=RE_IMG)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue