config rework & bigger images
This commit is contained in:
parent
c35fe495dc
commit
5e0f797a2f
6 changed files with 44 additions and 39 deletions
|
@ -39,7 +39,7 @@ class AdventImage:
|
||||||
# skalieren
|
# skalieren
|
||||||
return cls(
|
return cls(
|
||||||
img.resize(
|
img.resize(
|
||||||
size=(500, 500),
|
size=(1000, 1000),
|
||||||
resample=Image.LANCZOS,
|
resample=Image.LANCZOS,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -36,7 +36,7 @@ class CalendarConfig(BaseModel):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
await WebDAV.write_str(
|
await WebDAV.write_str(
|
||||||
path=f"files/{cfg.puzzle.calendar}",
|
path=f"files/{cfg.calendar}",
|
||||||
content=tomli_w.dumps(self.model_dump()),
|
content=tomli_w.dumps(self.model_dump()),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -48,5 +48,5 @@ async def get_calendar_config(
|
||||||
Kalender Konfiguration lesen
|
Kalender Konfiguration lesen
|
||||||
"""
|
"""
|
||||||
|
|
||||||
txt = await WebDAV.read_str(path=f"files/{cfg.puzzle.calendar}")
|
txt = await WebDAV.read_str(path=f"files/{cfg.calendar}")
|
||||||
return CalendarConfig.model_validate(tomllib.loads(txt))
|
return CalendarConfig.model_validate(tomllib.loads(txt))
|
||||||
|
|
|
@ -11,9 +11,13 @@ class User(BaseModel):
|
||||||
password: str
|
password: str
|
||||||
|
|
||||||
|
|
||||||
class Server(BaseModel):
|
class Puzzle(BaseModel):
|
||||||
# Dateiname Schriftart
|
# Titel
|
||||||
font: str
|
# TODO
|
||||||
|
title: str
|
||||||
|
|
||||||
|
# Lösungswort
|
||||||
|
solution: str
|
||||||
|
|
||||||
# Tag, an dem der Kalender startet
|
# Tag, an dem der Kalender startet
|
||||||
# TODO penner
|
# TODO penner
|
||||||
|
@ -28,12 +32,32 @@ class Server(BaseModel):
|
||||||
close_after: int = 90
|
close_after: int = 90
|
||||||
|
|
||||||
|
|
||||||
class Puzzle(BaseModel):
|
class TTFont(BaseModel):
|
||||||
# Titel
|
# Dateiname (in "/files")
|
||||||
title: str
|
file: str
|
||||||
|
|
||||||
# Lösungswort
|
# Schriftgröße für den Font
|
||||||
solution: str
|
size: int = 50
|
||||||
|
|
||||||
|
|
||||||
|
class Image(BaseModel):
|
||||||
|
# Quadrat, Seitenlänge in px
|
||||||
|
# TODO penner
|
||||||
|
size: int = 1000
|
||||||
|
|
||||||
|
# Rand in px, wo keine Buchstaben untergebracht werden
|
||||||
|
# TODO penner
|
||||||
|
border: int = 60
|
||||||
|
|
||||||
|
# Schriftarten
|
||||||
|
# TODO
|
||||||
|
fonts: list[TTFont]
|
||||||
|
|
||||||
|
|
||||||
|
class Config(BaseModel):
|
||||||
|
admin: User
|
||||||
|
puzzle: Puzzle
|
||||||
|
image: Image
|
||||||
|
|
||||||
# Kalenderdefinition
|
# Kalenderdefinition
|
||||||
calendar: str = "default.toml"
|
calendar: str = "default.toml"
|
||||||
|
@ -42,12 +66,6 @@ class Puzzle(BaseModel):
|
||||||
random_seed: str = ""
|
random_seed: str = ""
|
||||||
|
|
||||||
|
|
||||||
class Config(BaseModel):
|
|
||||||
admin: User
|
|
||||||
server: Server
|
|
||||||
puzzle: Puzzle
|
|
||||||
|
|
||||||
|
|
||||||
async def get_config() -> Config:
|
async def get_config() -> Config:
|
||||||
"""
|
"""
|
||||||
Globale Konfiguration lesen
|
Globale Konfiguration lesen
|
||||||
|
|
|
@ -113,14 +113,14 @@ async def gen_day_auto_image(
|
||||||
rnd = await Random.get(day)
|
rnd = await Random.get(day)
|
||||||
|
|
||||||
font = ImageFont.truetype(
|
font = ImageFont.truetype(
|
||||||
font=BytesIO(await WebDAV.read_bytes(f"files/{cfg.server.font}")),
|
font=BytesIO(await WebDAV.read_bytes("files/Lena.ttf")), # TODO
|
||||||
size=50,
|
size=100,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Buchstaben verstecken
|
# Buchstaben verstecken
|
||||||
for letter in day_parts[day]:
|
for letter in day_parts[day]:
|
||||||
await image.hide_text(
|
await image.hide_text(
|
||||||
xy=cast(_XY, tuple(rnd.choices(range(30, 470), k=2))),
|
xy=cast(_XY, tuple(rnd.choices(range(60, 940), k=2))),
|
||||||
text=letter,
|
text=letter,
|
||||||
font=font,
|
font=font,
|
||||||
)
|
)
|
||||||
|
|
|
@ -18,7 +18,7 @@ class Random(random.Random):
|
||||||
@classmethod
|
@classmethod
|
||||||
async def get(cls, bonus_salt: Any = "") -> Self:
|
async def get(cls, bonus_salt: Any = "") -> Self:
|
||||||
cfg = await get_config()
|
cfg = await get_config()
|
||||||
return cls(f"{cfg.puzzle.solution}{cfg.puzzle.random_seed}{bonus_salt}")
|
return cls(f"{cfg.puzzle.solution}{cfg.random_seed}{bonus_salt}")
|
||||||
|
|
||||||
def shuffled(self, population: Sequence[T]) -> Sequence[T]:
|
def shuffled(self, population: Sequence[T]) -> Sequence[T]:
|
||||||
return self.sample(population, k=len(population))
|
return self.sample(population, k=len(population))
|
||||||
|
|
|
@ -6,7 +6,7 @@ from pydantic import BaseModel
|
||||||
from advent22_api.core.helpers import EventDates
|
from advent22_api.core.helpers import EventDates
|
||||||
|
|
||||||
from ..core.calendar_config import CalendarConfig, DoorsSaved, get_calendar_config
|
from ..core.calendar_config import CalendarConfig, DoorsSaved, get_calendar_config
|
||||||
from ..core.config import Config, get_config
|
from ..core.config import Config, Image, get_config
|
||||||
from ..core.depends import get_all_event_dates, get_all_image_names, get_all_parts
|
from ..core.depends import get_all_event_dates, get_all_image_names, get_all_parts
|
||||||
from ..core.settings import SETTINGS
|
from ..core.settings import SETTINGS
|
||||||
from ._security import require_admin, user_is_admin
|
from ._security import require_admin, user_is_admin
|
||||||
|
@ -34,15 +34,6 @@ class ConfigModel(BaseModel):
|
||||||
config_file: str
|
config_file: str
|
||||||
background: str
|
background: str
|
||||||
|
|
||||||
class __Image(BaseModel):
|
|
||||||
class __Font(BaseModel):
|
|
||||||
file: str
|
|
||||||
size: int
|
|
||||||
|
|
||||||
size: int
|
|
||||||
border: int
|
|
||||||
fonts: list[__Font]
|
|
||||||
|
|
||||||
class __WebDAV(BaseModel):
|
class __WebDAV(BaseModel):
|
||||||
url: str
|
url: str
|
||||||
cache_ttl: int
|
cache_ttl: int
|
||||||
|
@ -50,7 +41,7 @@ class ConfigModel(BaseModel):
|
||||||
|
|
||||||
puzzle: __Puzzle
|
puzzle: __Puzzle
|
||||||
calendar: __Calendar
|
calendar: __Calendar
|
||||||
image: __Image
|
image: Image
|
||||||
webdav: __WebDAV
|
webdav: __WebDAV
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,17 +64,13 @@ async def get_config_model(
|
||||||
"next": event_dates.next,
|
"next": event_dates.next,
|
||||||
"last": event_dates.last,
|
"last": event_dates.last,
|
||||||
"end": event_dates.end,
|
"end": event_dates.end,
|
||||||
"seed": cfg.puzzle.random_seed,
|
"seed": cfg.random_seed,
|
||||||
},
|
},
|
||||||
"calendar": {
|
"calendar": {
|
||||||
"config_file": cfg.puzzle.calendar,
|
"config_file": cfg.calendar,
|
||||||
"background": cal_cfg.background,
|
"background": cal_cfg.background,
|
||||||
},
|
},
|
||||||
"image": {
|
"image": cfg.image,
|
||||||
"size": 500, # TODO
|
|
||||||
"border": 30, # TODO
|
|
||||||
"fonts": [{"file": cfg.server.font, "size": 50}], # TODO
|
|
||||||
},
|
|
||||||
"webdav": {
|
"webdav": {
|
||||||
"url": SETTINGS.webdav.url,
|
"url": SETTINGS.webdav.url,
|
||||||
"cache_ttl": SETTINGS.webdav.cache_ttl,
|
"cache_ttl": SETTINGS.webdav.cache_ttl,
|
||||||
|
|
Loading…
Reference in a new issue