mirror of
https://github.com/thekiwismarthome/shopping-list-manager.git
synced 2026-05-01 11:46:30 +00:00
Update category_loader.py
This commit is contained in:
@@ -3,12 +3,13 @@ import json
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from typing import List, Dict, Any
|
from typing import List, Dict, Any
|
||||||
|
import aiofiles
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def load_categories(component_path: str, country_code: str = None) -> List[Dict[str, Any]]:
|
async def load_categories(component_path: str, country_code: str = None) -> List[Dict[str, Any]]:
|
||||||
"""Load categories from JSON file.
|
"""Load categories from JSON file asynchronously.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
component_path: Path to the component directory
|
component_path: Path to the component directory
|
||||||
@@ -18,6 +19,8 @@ def load_categories(component_path: str, country_code: str = None) -> List[Dict[
|
|||||||
Returns:
|
Returns:
|
||||||
List of category dictionaries
|
List of category dictionaries
|
||||||
"""
|
"""
|
||||||
|
import os
|
||||||
|
|
||||||
# Try country-specific file first if country_code provided
|
# Try country-specific file first if country_code provided
|
||||||
if country_code:
|
if country_code:
|
||||||
country_file = os.path.join(
|
country_file = os.path.join(
|
||||||
@@ -36,8 +39,9 @@ def load_categories(component_path: str, country_code: str = None) -> List[Dict[
|
|||||||
categories_file = os.path.join(component_path, "data", "categories.json")
|
categories_file = os.path.join(component_path, "data", "categories.json")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(categories_file, "r", encoding="utf-8") as f:
|
async with aiofiles.open(categories_file, "r", encoding="utf-8") as f:
|
||||||
data = json.load(f)
|
content = await f.read()
|
||||||
|
data = json.loads(content)
|
||||||
|
|
||||||
_LOGGER.info(
|
_LOGGER.info(
|
||||||
"Loaded categories version %s for region %s",
|
"Loaded categories version %s for region %s",
|
||||||
|
|||||||
Reference in New Issue
Block a user