# CI/CD Workshop # Copyright (C) 2025 OpenBokeron # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import json import random from datetime import datetime from pathlib import Path from typing import Dict, List DATA_DIR = Path(__file__).resolve().parent.parent / "data" ITEMS_PER_SECTION = 3 def _load_json(filename: str) -> Dict: path = DATA_DIR / filename with open(path, encoding="utf-8") as file: return json.load(file) MENU_SOURCE = _load_json("menu_items.json") def _pick_items(options: List[str], count: int) -> List[str]: if count >= len(options): return list(options) return random.sample(options, count) def _pick_mains(count: int = ITEMS_PER_SECTION) -> List[str]: fish_options = MENU_SOURCE["mains"]["fish"] other_options = MENU_SOURCE["mains"]["others"] fish_choice = random.choice(fish_options) remaining_needed = max(count - 1, 0) pool = [item for item in fish_options if item != fish_choice] + other_options if remaining_needed > len(pool): remaining_needed = len(pool) mains = [fish_choice] + _pick_items(pool, remaining_needed) random.shuffle(mains) return mains def _pick_garnish() -> List[str]: garnish_options = MENU_SOURCE["mains"]["garnish"] return _pick_items(garnish_options, 2) def _build_alternative() -> Dict: alternative = MENU_SOURCE.get("alternatives", {}) return { "title": alternative.get("title", "Alternativa"), "items": alternative.get("items", []), "price": alternative.get("price"), "note": alternative.get("note", ""), } def build_menu(items_per_section: int = ITEMS_PER_SECTION) -> Dict: today = datetime.now() return { "day": today.strftime("%A").capitalize(), "starters": _pick_items(MENU_SOURCE["starters"], items_per_section), "mains": _pick_mains(items_per_section), "garnish": _pick_garnish(), "desserts": _pick_items(MENU_SOURCE["desserts"], items_per_section), "notes": _pick_items(MENU_SOURCE["notes"], 3), "menu_price": MENU_SOURCE["university_deal"]["current_price"], "university_deal": MENU_SOURCE["university_deal"], "espetos_tip": random.choice(MENU_SOURCE["espetos_tips"]), "alternative": _build_alternative(), "availability": { "last_updated": today.isoformat(timespec="seconds"), }, }