This commit is contained in:
jose-rZM
2025-12-15 11:42:17 +01:00
commit c3f7af7379
33 changed files with 5004 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
import json
import random
from datetime import datetime
from pathlib import Path
from typing import Dict
DATA_DIR = Path(__file__).resolve().parent.parent / "data"
def _load_json(filename: str) -> Dict:
path = DATA_DIR / filename
with open(path, encoding="utf-8") as file:
return json.load(file)
PRICE_RANGES = _load_json("price_ranges.json")["items"]
def random_price(item: str) -> Dict:
low, high = PRICE_RANGES.get(item, (1.0, 3.0))
price = min(round(random.uniform(low, high), 2), 3.0)
return {
"item": item,
"price": price,
"currency": "EUR",
"generated_at": datetime.now().isoformat(timespec="seconds"),
}
def prices_payload() -> Dict:
return {
"items": [random_price(item) for item in PRICE_RANGES.keys()],
"disclaimer": "Depende de como pilles al de cafete.",
}