initial: blog-app snapshot
This commit is contained in:
29
repositories/watchdog_repo.py
Normal file
29
repositories/watchdog_repo.py
Normal file
@@ -0,0 +1,29 @@
|
||||
"""Watchdog report queries (read against watchdog.db). No Flask imports."""
|
||||
|
||||
import json
|
||||
import logging
|
||||
import sqlite3
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def list_reports(watchdog_conn, days=7):
|
||||
"""Return recent watchdog reports; rows include parsed `meta` dict.
|
||||
|
||||
Raises sqlite3.Error on read failure — the caller (service layer) decides
|
||||
how to degrade.
|
||||
"""
|
||||
cur = watchdog_conn.execute(
|
||||
"SELECT date, markdown, meta_json, created_at FROM reports "
|
||||
"ORDER BY date DESC LIMIT ?",
|
||||
(days,),
|
||||
)
|
||||
reports = []
|
||||
for row in cur.fetchall():
|
||||
item = dict(row)
|
||||
try:
|
||||
item["meta"] = json.loads(item.get("meta_json") or "{}")
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
item["meta"] = {}
|
||||
reports.append(item)
|
||||
return reports
|
||||
Reference in New Issue
Block a user