2023-09-07 16:44:44 +00:00
|
|
|
import tomllib
|
|
|
|
from typing import TypeAlias
|
|
|
|
|
|
|
|
import tomli_w
|
2022-11-04 18:49:31 +00:00
|
|
|
from pydantic import BaseModel
|
|
|
|
|
2023-09-07 16:44:44 +00:00
|
|
|
from .dav_common import dav_get_textfile_content, dav_write_textfile_content
|
2022-11-04 18:49:31 +00:00
|
|
|
from .settings import SETTINGS
|
|
|
|
|
|
|
|
|
2022-11-15 22:17:32 +00:00
|
|
|
class User(BaseModel):
|
|
|
|
name: str
|
|
|
|
password: str
|
|
|
|
|
|
|
|
|
2023-09-07 19:34:11 +00:00
|
|
|
class DoorSaved(BaseModel):
|
2023-09-07 21:05:00 +00:00
|
|
|
# Tag, an dem die Tür aufgeht
|
2023-09-07 16:44:44 +00:00
|
|
|
day: int
|
2023-09-07 21:05:00 +00:00
|
|
|
|
|
|
|
# Koordinaten für zwei Eckpunkte
|
2023-09-07 16:44:44 +00:00
|
|
|
x1: int
|
|
|
|
y1: int
|
|
|
|
x2: int
|
|
|
|
y2: int
|
|
|
|
|
|
|
|
|
2023-09-07 19:34:11 +00:00
|
|
|
DoorsSaved: TypeAlias = list[DoorSaved]
|
|
|
|
|
|
|
|
|
|
|
|
class Puzzle(BaseModel):
|
2023-09-07 21:05:00 +00:00
|
|
|
# Dateiname Hintergrundbild
|
2023-09-07 19:34:11 +00:00
|
|
|
background: str
|
2023-09-07 21:05:00 +00:00
|
|
|
|
|
|
|
# Dateiname Schriftart
|
2023-09-07 19:34:11 +00:00
|
|
|
font: str
|
2023-09-07 21:05:00 +00:00
|
|
|
|
|
|
|
# Türen für die UI
|
|
|
|
doors: DoorsSaved = []
|
|
|
|
|
|
|
|
# Lösungswort
|
2023-09-07 19:34:11 +00:00
|
|
|
solution: str
|
2023-09-07 16:44:44 +00:00
|
|
|
|
2023-09-07 21:05:00 +00:00
|
|
|
# Monat, während dem der Kalender läuft
|
|
|
|
month: int = 12
|
|
|
|
|
|
|
|
# Letzter Tag des Kalenders
|
|
|
|
max_day: int = 24
|
|
|
|
|
|
|
|
# Alle Türen bleiben noch so viele Monate offen
|
|
|
|
keep_open: int = 3
|
|
|
|
|
2023-09-07 16:44:44 +00:00
|
|
|
|
2022-11-04 18:49:31 +00:00
|
|
|
class Config(BaseModel):
|
2022-11-15 22:17:32 +00:00
|
|
|
admin: User
|
2022-11-18 01:39:05 +00:00
|
|
|
puzzle: Puzzle
|
2022-11-04 18:49:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def get_config() -> Config:
|
|
|
|
txt = await dav_get_textfile_content(path=SETTINGS.config_filename)
|
|
|
|
|
2023-09-07 16:44:44 +00:00
|
|
|
return Config.model_validate(tomllib.loads(txt))
|
|
|
|
|
|
|
|
|
|
|
|
async def set_config(cfg: Config) -> None:
|
|
|
|
txt = tomli_w.dumps(cfg.model_dump())
|
|
|
|
|
|
|
|
await dav_write_textfile_content(
|
|
|
|
path=SETTINGS.config_filename,
|
|
|
|
content=txt,
|
|
|
|
)
|