Config Abschnitt "Puzzle"

This commit is contained in:
Jörn-Michael Miehe 2022-11-18 01:39:05 +00:00
parent e9232fdcac
commit 9f81895600
3 changed files with 10 additions and 6 deletions

View file

@ -10,9 +10,13 @@ class User(BaseModel):
password: str
class Puzzle(BaseModel):
solution: str
class Config(BaseModel):
admin: User
solution: str
puzzle: Puzzle
async def get_config() -> Config:

View file

@ -17,7 +17,7 @@ from ._image import AdventImage
async def get_rnd(bonus_salt: Any = "") -> random.Random:
cfg = await get_config()
return random.Random(f"{cfg.solution}{bonus_salt}")
return random.Random(f"{cfg.puzzle.solution}{bonus_salt}")
async def set_length(seq: Sequence, length: int) -> list:
@ -44,7 +44,7 @@ async def get_letter(
index: int,
cfg: Config = Depends(get_config),
) -> str:
return (await shuffle(cfg.solution))[index]
return (await shuffle(cfg.puzzle.solution))[index]
_RE_IMAGE_FILE = re.compile(

View file

@ -15,8 +15,8 @@ router = APIRouter(prefix="/days", tags=["days"])
@router.on_event("startup")
async def startup() -> None:
cfg = await get_config()
print(cfg.solution)
print("".join(await shuffle(cfg.solution)))
print(cfg.puzzle.solution)
print("".join(await shuffle(cfg.puzzle.solution)))
@router.get("/letter/{index}")
@ -24,7 +24,7 @@ async def get_letter(
index: int,
cfg: Config = Depends(get_config),
) -> str:
return (await shuffle(cfg.solution))[index]
return (await shuffle(cfg.puzzle.solution))[index]
@router.get("/date")