mejora de la semantica
This commit is contained in:
parent
d508dc2058
commit
cb8f69fb93
10 changed files with 191 additions and 227 deletions
21
app.py
21
app.py
|
|
@ -224,7 +224,6 @@ def _process_feed(feed_row):
|
|||
except psycopg2.Error as e:
|
||||
app.logger.warning(f"[ingesta] Error insertando noticia de {feed_url}: {e}")
|
||||
|
||||
# Si ha ido bien, reseteamos fallos
|
||||
with get_conn() as conn, conn.cursor() as cur:
|
||||
cur.execute(
|
||||
"UPDATE feeds SET fallos = 0 WHERE id = %s;",
|
||||
|
|
@ -236,7 +235,6 @@ def _process_feed(feed_row):
|
|||
except Exception as e:
|
||||
app.logger.exception(f"[ingesta] Error procesando feed {feed_id} ({feed_url}): {e}")
|
||||
try:
|
||||
# Incrementamos fallos y marcamos inactivo si supera RSS_MAX_FAILURES
|
||||
with get_conn() as conn, conn.cursor() as cur:
|
||||
cur.execute(
|
||||
"""
|
||||
|
|
@ -818,11 +816,6 @@ def restore_feeds():
|
|||
return redirect(url_for("restore_feeds"))
|
||||
|
||||
def parse_int_field(row, key):
|
||||
"""
|
||||
Intenta convertir row[key] a int.
|
||||
- Si está vacío -> None
|
||||
- Si no es convertible (p.ej. 'categoria_id') -> None y log de aviso
|
||||
"""
|
||||
val = row.get(key)
|
||||
if val is None or str(val).strip() == "":
|
||||
return None
|
||||
|
|
@ -842,6 +835,18 @@ def restore_feeds():
|
|||
categoria_id = parse_int_field(row, "categoria_id")
|
||||
pais_id = parse_int_field(row, "pais_id")
|
||||
|
||||
raw_fallos = (row.get("fallos") or "").strip()
|
||||
if raw_fallos == "":
|
||||
fallos = 0
|
||||
else:
|
||||
try:
|
||||
fallos = int(raw_fallos)
|
||||
except (ValueError, TypeError):
|
||||
app.logger.warning(
|
||||
f"[restore_feeds] Valor no numérico '{raw_fallos}' en columna fallos, se usará 0."
|
||||
)
|
||||
fallos = 0
|
||||
|
||||
cur.execute(
|
||||
"""
|
||||
INSERT INTO feeds (nombre, descripcion, url, categoria_id, pais_id, idioma, activo, fallos)
|
||||
|
|
@ -863,7 +868,7 @@ def restore_feeds():
|
|||
pais_id,
|
||||
(row.get("idioma") or "").strip().lower()[:2] or None,
|
||||
row.get("activo") in ("1", "True", "true", "t", "on"),
|
||||
int(row.get("fallos") or 0),
|
||||
fallos,
|
||||
),
|
||||
)
|
||||
conn.commit()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue