| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import json
- import os
- from typing import List, Dict
- from venv import logger
- from config.settings import BG_DATA_PATH, PRODUCTS_PATH, EXCLUDED_BEER_IDS
- from logging import getLogger
- logger = getLogger(__name__)
- def load_bg_data() -> List[Dict[str, str]]:
- """Load background data for AI assistant"""
- try:
- with open(BG_DATA_PATH, 'r', encoding='utf-8') as f:
- return json.load(f)
- except FileNotFoundError:
- logger.error(f"Data file not found at {BG_DATA_PATH}. Serving with empty data.")
- return []
- except json.JSONDecodeError:
- logger.error(f"Could not decode JSON from {BG_DATA_PATH}. Serving with empty data.")
- return []
- def load_products() -> List[Dict[str, str]]:
- """Load products data excluding beer IDs"""
- try:
- with open(PRODUCTS_PATH, 'r', encoding='utf-8') as f:
- products = json.load(f)
- return list(filter(lambda product: product['id'] not in EXCLUDED_BEER_IDS, products))
- except FileNotFoundError:
- logger.error(f"Data file not found at {PRODUCTS_PATH}. Serving with empty data.")
- return []
- except json.JSONDecodeError:
- logger.error(f"Could not decode JSON from {PRODUCTS_PATH}. Serving with empty data.")
- return []
- def load_users() -> List[Dict[str, str]]:
- """Load users data"""
- try:
- with open('users.json', 'r') as f:
- return json.load(f)
- except FileNotFoundError:
- logger.error("ERROR: users.json file not found.")
- return []
- except json.JSONDecodeError:
- logger.error("ERROR: Could not decode JSON from users.json.")
- return []
- # Load data at module level
- bg_data_loaded = load_bg_data()
- all_products = load_products()
|