#!/usr/bin/env python3
"""Thin wrapper — delegates to oracle.recency filter_fresh + analysis."""
import sys, os
sys.path.insert(0, os.path.dirname(__file__))

from datetime import datetime, timezone
from oracle.clickability import fetch_items, compute_index, decay_index
from oracle.recency import filter_fresh, blend_score
import sqlite3
from oracle.config import DB_PATH, HALF_LIFE_H

conn = sqlite3.connect(str(DB_PATH))
items = fetch_items(conn)
conn.close()

items = compute_index(items)
items = decay_index(items, HALF_LIFE_H)

today, older_new, dropped = filter_fresh(items)

print(f"=== Recency Guard ===")
print(f"  Total items: {len(items)}")
print(f"  TODAY (always eligible): {len(today)}")
print(f"  OLDER but never posted:  {len(older_new)}")
print(f"  DROPPED (posted + old):   {len(dropped)}")
print()

for it in sorted(today, key=lambda x: x["clickability_decayed"], reverse=True)[:5]:
    print(f"  [TODAY {it['clickability_decayed']:.2f}] {it['source']:10} {it['title'][:60]}")
