MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / get_recent_created_report

Function get_recent_created_report

skills/storage-helper/scripts/db_ops.py:973–1002  ·  view source on GitHub ↗

Return the latest created reading report for a user.

(
    user_id: str,
    *,
    minutes: int = 180,
)

Source from the content-addressed store, hash-verified

971
972def get_recent_created_report_by_source(
973 user_id: str,
974 source_type: str,
975 source_key: str,
976 days: int = 30,
977) -> Optional[Dict[str, Any]]:
978 """
979 Find the latest created reading-report document for a source descriptor.
980
981 Source metadata is stored in behavior_logs.metadata under:
982 - report_source_type
983 - report_source_key
984 """
985 normalized_source_type = _normalize_identifier(source_type)
986 normalized_source_key = _normalize_identifier(source_key)
987 if not normalized_source_type or not normalized_source_key:
988 return None
989
990 since_date = (datetime.now() - timedelta(days=max(1, int(days)))).isoformat(sep=" ")
991 conn = get_connection()
992 cursor = conn.cursor()
993 cursor.execute(
994 """
995 SELECT bl.paper_id, bl.timestamp, bl.metadata, p.title AS paper_title
996 FROM behavior_logs bl
997 LEFT JOIN papers p ON p.id = bl.paper_id
998 WHERE bl.user_id = ?
999 AND bl.action = 'created_report'
1000 AND bl.action_type = 'reading'
1001 AND bl.timestamp >= ?
1002 ORDER BY bl.timestamp DESC, bl.id DESC
1003 """,
1004 (user_id, since_date),
1005 )

Callers 1

Calls 6

nowMethod · 0.80
cursorMethod · 0.80
get_connectionFunction · 0.70
executeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected