Format/Lint

This commit is contained in:
2026-03-05 06:06:01 +00:00
parent 5941c41296
commit db879cee9f
6 changed files with 102 additions and 57 deletions

View File

@@ -58,9 +58,7 @@ class NotificationService:
"""
try:
# Query Firestore document by phone number
doc_ref = self._db.collection(self._collection_path).document(
phone_number
)
doc_ref = self._db.collection(self._collection_path).document(phone_number)
doc = await doc_ref.get()
if not doc.exists:
@@ -78,9 +76,7 @@ class NotificationService:
# Filter notifications that have NOT been notified by the agent
pending = [
n
for n in all_notifications
if not n.get("notified_by_agent", False)
n for n in all_notifications if not n.get("notified_by_agent", False)
]
if not pending:
@@ -90,9 +86,7 @@ class NotificationService:
return []
# Sort by timestamp_creacion (most recent first)
pending.sort(
key=lambda n: n.get("timestamp_creacion", 0), reverse=True
)
pending.sort(key=lambda n: n.get("timestamp_creacion", 0), reverse=True)
# Return top N most recent
result = pending[: self._max_to_notify]
@@ -104,13 +98,13 @@ class NotificationService:
len(result),
)
return result
except Exception:
logger.exception(
"Failed to fetch notifications for phone: %s", phone_number
)
return []
else:
return result
async def mark_as_notified(
self, phone_number: str, notification_ids: list[str]
@@ -133,9 +127,7 @@ class NotificationService:
return True
try:
doc_ref = self._db.collection(self._collection_path).document(
phone_number
)
doc_ref = self._db.collection(self._collection_path).document(phone_number)
doc = await doc_ref.get()
if not doc.exists:
@@ -184,18 +176,16 @@ class NotificationService:
phone_number,
)
return True
except Exception:
logger.exception(
"Failed to mark notifications as notified for phone: %s",
phone_number,
)
return False
else:
return True
def format_notification_summary(
self, notifications: list[dict[str, Any]]
) -> str:
def format_notification_summary(self, notifications: list[dict[str, Any]]) -> str:
"""Format notifications into a human-readable summary.
Args:
@@ -209,9 +199,7 @@ class NotificationService:
return ""
count = len(notifications)
summary_lines = [
f"El usuario tiene {count} notificación(es) pendiente(s):"
]
summary_lines = [f"El usuario tiene {count} notificación(es) pendiente(s):"]
for i, notif in enumerate(notifications, 1):
texto = notif.get("texto", "Sin texto")