mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2024-11-26 17:33:00 +00:00
57 lines
1.2 KiB
Python
57 lines
1.2 KiB
Python
import tomllib
|
|
from typing import TypeAlias
|
|
|
|
import tomli_w
|
|
from fastapi import Depends
|
|
from pydantic import BaseModel
|
|
|
|
from .config import Config, get_config
|
|
from .webdav import WebDAV
|
|
|
|
|
|
class DoorSaved(BaseModel):
|
|
# Tag, an dem die Tür aufgeht
|
|
day: int
|
|
|
|
# Koordinaten für zwei Eckpunkte
|
|
x1: int
|
|
y1: int
|
|
x2: int
|
|
y2: int
|
|
|
|
|
|
DoorsSaved: TypeAlias = list[DoorSaved]
|
|
|
|
|
|
class CalendarConfig(BaseModel):
|
|
# Dateiname Hintergrundbild
|
|
background: str = "adventskalender.jpg"
|
|
|
|
# Türen für die UI
|
|
doors: DoorsSaved = []
|
|
|
|
async def change(self, cfg: Config) -> None:
|
|
"""
|
|
Kalender Konfiguration ändern
|
|
"""
|
|
|
|
await WebDAV.write_str(
|
|
path=f"files/{cfg.puzzle.calendar}",
|
|
content=tomli_w.dumps(
|
|
self.model_dump(
|
|
exclude_defaults=True,
|
|
exclude_unset=True,
|
|
)
|
|
),
|
|
)
|
|
|
|
|
|
async def get_calendar_config(
|
|
cfg: Config = Depends(get_config),
|
|
) -> CalendarConfig:
|
|
"""
|
|
Kalender Konfiguration lesen
|
|
"""
|
|
|
|
txt = await WebDAV.read_str(path=f"files/{cfg.puzzle.calendar}")
|
|
return CalendarConfig.model_validate(tomllib.loads(txt))
|