Initial clean commit

This commit is contained in:
jlimolina 2026-01-13 13:39:51 +01:00
commit 6784d81c2c
141 changed files with 25219 additions and 0 deletions

44
routers/notifications.py Normal file
View file

@ -0,0 +1,44 @@
"""
Notifications router - Check for new important news.
"""
from flask import Blueprint, jsonify, request
from db import get_conn
from datetime import datetime
notifications_bp = Blueprint("notifications", __name__, url_prefix="/api/notifications")
@notifications_bp.route("/check")
def check_notifications():
"""Check for new news since a given timestamp."""
last_check = request.args.get("last_check")
if not last_check:
return jsonify({"has_news": False, "timestamp": datetime.utcnow().isoformat()})
try:
# Check for news created after last_check
# We define "important" as having translation or high score (if score existed)
# For now, just any new news to demonstrate functionality
with get_conn() as conn:
with conn.cursor() as cur:
cur.execute("""
SELECT COUNT(*), MAX(fecha)
FROM noticias
WHERE fecha > %s
""", (last_check,))
row = cur.fetchone()
count = row[0]
latest = row[1]
if count > 0:
return jsonify({
"has_news": True,
"count": count,
"timestamp": latest.isoformat() if latest else datetime.utcnow().isoformat(),
"message": f"¡{count} noticias nuevas encontradas!"
})
except Exception as e:
print(f"Error checking notifications: {e}")
return jsonify({"has_news": False, "timestamp": datetime.utcnow().isoformat()})