Spaces:
Runtime error
Runtime error
| from __future__ import annotations | |
| from datetime import date | |
| from typing import Any | |
| def parse_odds(form: dict[str, str]) -> dict[str, float]: | |
| if form.get("use_odds") != "on": | |
| return {} | |
| return { | |
| "home_odds": _required_float(form, "home_odds"), | |
| "draw_odds": _required_float(form, "draw_odds"), | |
| "away_odds": _required_float(form, "away_odds"), | |
| } | |
| def custom_match_row(form: dict[str, str]) -> dict[str, Any]: | |
| row: dict[str, Any] = { | |
| "date": form.get("date") or date.today().isoformat(), | |
| "home_team": form["home_team"], | |
| "away_team": form["away_team"], | |
| "tournament": form.get("tournament") or "World Cup", | |
| "round": form.get("round") or "Group Stage", | |
| "neutral": form.get("neutral") == "on", | |
| } | |
| row.update(parse_odds(form)) | |
| return row | |
| def _required_float(form: dict[str, str], key: str) -> float: | |
| value = form.get(key) | |
| if value in {None, ""}: | |
| raise ValueError(f"Missing {key}") | |
| parsed = float(value) | |
| if parsed <= 1: | |
| raise ValueError(f"{key} must be greater than 1") | |
| return parsed | |