mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2024-11-23 08:13:01 +00:00
51 lines
912 B
Python
51 lines
912 B
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):
|
|
day: int
|
|
x1: int
|
|
y1: int
|
|
x2: int
|
|
y2: int
|
|
|
|
|
|
DoorsSaved: TypeAlias = list[DoorSaved]
|
|
|
|
|
|
class Puzzle(BaseModel):
|
|
background: str
|
|
doors: DoorsSaved = []
|
|
font: str
|
|
solution: str
|
|
|
|
|
|
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,
|
|
)
|