advent22/api/advent22_api/core/config.py

55 lines
963 B
Python
Raw Normal View History

import tomllib
2022-11-04 18:49:31 +00:00
from pydantic import BaseModel
from .settings import SETTINGS
from .webdav import WebDAV
2022-11-04 18:49:31 +00:00
2022-11-15 22:17:32 +00:00
class User(BaseModel):
name: str
password: str
2023-09-08 00:56:14 +00:00
class Server(BaseModel):
# Dateiname Schriftart
font: str
2023-09-07 16:44:44 +00:00
2023-09-08 00:56:14 +00:00
# Monat, während dem der Kalender läuft
2023-09-08 10:23:43 +00:00
# TODO penner
2023-09-08 00:56:14 +00:00
month: int = 12
2023-09-07 16:44:44 +00:00
2023-09-08 00:56:14 +00:00
# Alle Türen bleiben noch so viele Monate offen
2023-09-08 10:23:43 +00:00
# TODO penner
2023-09-08 00:56:14 +00:00
keep_open: int = 3
2023-09-07 19:34:11 +00:00
class Puzzle(BaseModel):
2023-09-07 21:05:00 +00:00
# Lösungswort
2023-09-07 19:34:11 +00:00
solution: str
2023-09-07 16:44:44 +00:00
2023-09-08 00:56:14 +00:00
# Länge des Kalenders
2023-09-08 10:23:43 +00:00
# TODO penner
2023-09-08 00:56:14 +00:00
days: int = 24
2023-09-07 21:05:00 +00:00
2023-09-08 00:56:14 +00:00
# Kalenderdefinition
calendar: str = "default.toml"
2023-09-07 21:05:00 +00:00
2023-09-08 00:56:14 +00:00
# Serverseitiger zusätzlicher "random" seed
random_pepper: str = ""
2023-09-07 21:05:00 +00:00
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
2023-09-08 00:56:14 +00:00
server: Server
2022-11-18 01:39:05 +00:00
puzzle: Puzzle
async def get_config() -> "Config":
"""
Globale Konfiguration lesen
"""
txt = await WebDAV.read_str(path=SETTINGS.config_filename)
return Config.model_validate(tomllib.loads(txt))