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

Function get_push_for_date

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

Get the latest real push for a user on a specific local date. Args: user_id: User ID target_date: YYYY-MM-DD date string Returns: Push information with papers list, or None when no push exists that day

(user_id: str, target_date: str)

Source from the content-addressed store, hash-verified

1369 ORDER BY timestamp DESC, push_id DESC
1370 LIMIT 1
1371 """, (user_id,))
1372
1373 row = cursor.fetchone()
1374 if not row:
1375 conn.close()
1376 return None
1377
1378 push_id = row['push_id']
1379 push_time = row['timestamp']
1380
1381 # Get all papers in this push with their category and rank from metadata.
1382 cursor.execute("""
1383 SELECT p.*, bl.id as behavior_log_id, bl.metadata as bl_metadata FROM papers p
1384 JOIN behavior_logs bl ON p.id = bl.paper_id
1385 WHERE bl.user_id = ? AND bl.push_id = ? AND bl.action = 'pushed'
1386 ORDER BY bl.id ASC
1387 """, (user_id, push_id))
1388
1389 papers = [_build_paper_dict(row, metadata_key="bl_metadata") for row in cursor.fetchall()]
1390 papers.sort(key=lambda paper: (paper.get("rank", 10**9), paper.get("behavior_log_id", 10**9)))
1391
1392 cursor.execute(
1393 """
1394 SELECT metadata
1395 FROM behavior_logs
1396 WHERE user_id = ?
1397 AND push_id = ?
1398 AND action = 'push_empty'
1399 ORDER BY id DESC
1400 LIMIT 1
1401 """,
1402 (user_id, push_id),
1403 )
1404 metadata_row = cursor.fetchone()
1405 push_metadata = _load_json_metadata(metadata_row["metadata"]) if metadata_row else {}
1406 if not push_metadata:
1407 push_metadata = _derive_push_metadata_from_papers(papers)
1408
1409 conn.close()
1410
1411 return {
1412 "push_id": push_id,
1413 "push_time": push_time,
1414 "papers": papers,
1415 "metadata": push_metadata,
1416 }
1417
1418
1419def get_push_for_date(user_id: str, target_date: str) -> Optional[Dict]:
1420 """
1421 Get the latest real push for a user on a specific local date.
1422
1423 Args:
1424 user_id: User ID
1425 target_date: YYYY-MM-DD date string
1426
1427 Returns:
1428 Push information with papers list, or None when no push exists that day

Callers

nothing calls this directly

Calls 9

_build_paper_dictFunction · 0.85
_load_json_metadataFunction · 0.85
cursorMethod · 0.80
getMethod · 0.80
get_connectionFunction · 0.70
executeMethod · 0.45
closeMethod · 0.45
fetchallMethod · 0.45

Tested by

no test coverage detected