diff options
| author | cashmere <cashmere@autistici.org> | 2026-06-19 23:43:38 +0200 |
|---|---|---|
| committer | cashmere <cashmere@autistici.org> | 2026-06-19 23:43:38 +0200 |
| commit | 55c2e85bd0f2ccf9c78caa7714a7f3233d342317 (patch) | |
| tree | 4cd7802b6cf8897e758428c9c7daf57822d9c067 /src/technical_renaissance | |
| parent | 898cbc708f87225b78bc718381c0f5d9a9a75f20 (diff) | |
| download | technical-renaissance-55c2e85bd0f2ccf9c78caa7714a7f3233d342317.tar.gz | |
app.py: finish last changes
Diffstat (limited to 'src/technical_renaissance')
| -rw-r--r-- | src/technical_renaissance/app.py | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/src/technical_renaissance/app.py b/src/technical_renaissance/app.py index fa1037a..3e8ccbc 100644 --- a/src/technical_renaissance/app.py +++ b/src/technical_renaissance/app.py @@ -1,16 +1,15 @@ import os import pathlib -from robyn.templating import JinjaTemplate -from typing import cast +import random import tomllib from pathlib import Path -from robyn import Request -from robyn import Robyn from typing import TypedDict +from robyn import Request, Response, Robyn +from robyn.templating import JinjaTemplate + User = TypedDict("User", {"name": str, "url": str, "description": str}) -Config = TypedDict("Config", {"user": list[User]}) def load_users(path: Path) -> list[User]: @@ -20,19 +19,33 @@ def load_users(path: Path) -> list[User]: current_file_path = pathlib.Path(__file__).parent.resolve() users = load_users(current_file_path / "config.toml") + app = Robyn(__file__) app.serve_directory( route="/static", - directory_path="./static", + directory_path=os.path.join(current_file_path, "static"), ) -current_file_path = pathlib.Path(__file__).parent.resolve() JINJA_TEMPLATE = JinjaTemplate(os.path.join(current_file_path, "templates")) +def index_of(request: Request) -> int: + name = request.query_params.get("from", "") + for i, user in enumerate(users): + if user["name"] == name: + return i + return 0 + + +def redirect(url: str) -> Response: + return Response(status_code=302, headers={"Location": url}, description="") + + @app.get("/") -async def root(_request: Request): - return "Hello World" +async def index(_request: Request): + return JINJA_TEMPLATE.render_template("index.html", users=users) + + @app.get("/next") async def next_user(request: Request): current = index_of(request) |
