70 lines
1.3 KiB
Python
70 lines
1.3 KiB
Python
import tomllib
|
|
from typing import TypeAlias
|
|
|
|
import tomli_w
|
|
from pydantic import BaseModel
|
|
|
|
from .dav_common import dav_get_textfile_content, dav_write_textfile_content
|
|
from .settings import SETTINGS
|
|
|
|
|
|
class User(BaseModel):
|
|
name: str
|
|
password: str
|
|
|
|
|
|
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 Puzzle(BaseModel):
|
|
# Dateiname Hintergrundbild
|
|
background: str
|
|
|
|
# Dateiname Schriftart
|
|
font: str
|
|
|
|
# Türen für die UI
|
|
doors: DoorsSaved = []
|
|
|
|
# Lösungswort
|
|
solution: str
|
|
|
|
# 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
|
|
|
|
|
|
class Config(BaseModel):
|
|
admin: User
|
|
puzzle: Puzzle
|
|
|
|
|
|
async def get_config() -> Config:
|
|
txt = await dav_get_textfile_content(path=SETTINGS.config_filename)
|
|
|
|
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,
|
|
)
|