advent22/api/advent22_api/routers/_misc.py

21 lines
509 B
Python

import itertools
import random
from typing import Sequence
from ..dav_common import dav_get_file
async def get_loesungswort() -> str:
fp = await dav_get_file("loesungswort.txt")
return fp.read().decode("utf8").strip()
async def set_length(seq: Sequence, length: int) -> list:
infinite = itertools.cycle(seq)
return list(itertools.islice(infinite, length))
async def shuffle(seq: Sequence) -> list:
rnd = random.Random(await get_loesungswort())
return rnd.sample(seq, len(seq))