Fix lint errors
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
"""Quick reply content service for loading FAQ screens."""
|
||||
|
||||
import json
|
||||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
from capa_de_integracion.config import Settings
|
||||
from capa_de_integracion.models.quick_replies import (
|
||||
@@ -24,9 +27,17 @@ class QuickReplyContentService:
|
||||
self.quick_replies_path = settings.base_path / "quick_replies"
|
||||
|
||||
logger.info(
|
||||
f"QuickReplyContentService initialized with path: {self.quick_replies_path}",
|
||||
"QuickReplyContentService initialized with path: %s",
|
||||
self.quick_replies_path,
|
||||
)
|
||||
|
||||
def _validate_file(self, file_path: Path, screen_id: str) -> None:
|
||||
"""Validate that the quick reply file exists."""
|
||||
if not file_path.exists():
|
||||
logger.warning("Quick reply file not found: %s", file_path)
|
||||
msg = f"Quick reply file not found for screen_id: {screen_id}"
|
||||
raise ValueError(msg)
|
||||
|
||||
async def get_quick_replies(self, screen_id: str) -> QuickReplyScreen:
|
||||
"""Load quick reply screen content by ID.
|
||||
|
||||
@@ -53,15 +64,11 @@ class QuickReplyContentService:
|
||||
file_path = self.quick_replies_path / f"{screen_id}.json"
|
||||
|
||||
try:
|
||||
if not file_path.exists():
|
||||
logger.warning(f"Quick reply file not found: {file_path}")
|
||||
msg = f"Quick reply file not found for screen_id: {screen_id}"
|
||||
raise ValueError(
|
||||
msg,
|
||||
)
|
||||
self._validate_file(file_path, screen_id)
|
||||
|
||||
with open(file_path, encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
# Use Path.read_text() for async-friendly file reading
|
||||
content = file_path.read_text(encoding="utf-8")
|
||||
data = json.loads(content)
|
||||
|
||||
# Parse questions
|
||||
preguntas_data = data.get("preguntas", [])
|
||||
@@ -83,22 +90,17 @@ class QuickReplyContentService:
|
||||
)
|
||||
|
||||
logger.info(
|
||||
f"Successfully loaded {len(preguntas)} quick replies for screen: {screen_id}",
|
||||
"Successfully loaded %s quick replies for screen: %s",
|
||||
len(preguntas),
|
||||
screen_id,
|
||||
)
|
||||
return quick_reply
|
||||
|
||||
except json.JSONDecodeError as e:
|
||||
logger.error(f"Error parsing JSON file {file_path}: {e}", exc_info=True)
|
||||
logger.exception("Error parsing JSON file %s", file_path)
|
||||
msg = f"Invalid JSON format in quick reply file for screen_id: {screen_id}"
|
||||
raise ValueError(
|
||||
msg,
|
||||
) from e
|
||||
raise ValueError(msg) from e
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
f"Error loading quick replies for screen {screen_id}: {e}",
|
||||
exc_info=True,
|
||||
)
|
||||
logger.exception("Error loading quick replies for screen %s", screen_id)
|
||||
msg = f"Error loading quick replies for screen_id: {screen_id}"
|
||||
raise ValueError(
|
||||
msg,
|
||||
) from e
|
||||
raise ValueError(msg) from e
|
||||
else:
|
||||
return quick_reply
|
||||
|
||||
Reference in New Issue
Block a user