mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2024-11-22 15:53:01 +00:00
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
|
||||
|
||||
- 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
|
||||
|
||||
|
|
|
@ -10,7 +10,14 @@ from .advent_image import _XY, AdventImage
|
|||
from .calendar_config import CalendarConfig, get_calendar_config
|
||||
from .config import Config, get_config
|
||||
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(
|
||||
|
@ -87,19 +94,17 @@ async def get_all_auto_image_names(
|
|||
|
||||
async def get_all_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]:
|
||||
"""
|
||||
Bilder "auto" und "manual" zu Tagen zuordnen
|
||||
"""
|
||||
|
||||
__DIR = "/images_manual"
|
||||
__RE = re.compile(r"\.jpg$", flags=re.IGNORECASE)
|
||||
|
||||
manual_image_names = await WebDAV.list_files(directory=__DIR, regex=__RE)
|
||||
num_re = re.compile(r"/(\d+)\.", flags=re.IGNORECASE)
|
||||
|
||||
for name in manual_image_names:
|
||||
zahl = int(__RE.sub(string=name, repl=""))
|
||||
auto_image_names[zahl] = f"{__DIR}/{name}"
|
||||
assert (num_match := num_re.search(name)) is not None
|
||||
auto_image_names[int(num_match.group(1))] = name
|
||||
|
||||
return auto_image_names
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ from .config import get_config
|
|||
from .dav.webdav import WebDAV
|
||||
|
||||
T = TypeVar("T")
|
||||
RE_IMG = re.compile(r"\.(gif|jpe?g|tiff?|png|bmp)$", flags=re.IGNORECASE)
|
||||
|
||||
|
||||
class Random(random.Random):
|
||||
|
@ -88,10 +89,20 @@ async def list_images_auto() -> list[str]:
|
|||
|
||||
return [
|
||||
f"{__DIR}/{file}"
|
||||
for file in await WebDAV.list_files(
|
||||
directory=__DIR,
|
||||
regex=re.compile(r"\.(gif|jpe?g|tiff?|png|bmp)$", flags=re.IGNORECASE),
|
||||
)
|
||||
for file in await WebDAV.list_files(directory=__DIR, regex=RE_IMG)
|
||||
]
|
||||
|
||||
|
||||
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