tokiospg commited on
Commit
af0aca2
·
verified ·
1 Parent(s): 500de74

Upload database.py

Browse files
Files changed (1) hide show
  1. database.py +11 -11
database.py CHANGED
@@ -148,7 +148,7 @@ def init_db():
148
  if not c.fetchone():
149
  salt = bcrypt.gensalt()
150
  hashed_pw = bcrypt.hashpw(b"admin", salt).decode('utf-8')
151
- c.execute("INSERT INTO users VALUES ('admin', ?, 'Gerencia', '', '', '', '')", (hashed_pw,))
152
 
153
  conn.commit()
154
  conn.close()
@@ -307,7 +307,7 @@ def registrar_intento_fallido(username: str):
307
  intentos = c.fetchone()[0]
308
  if intentos >= MAX_INTENTOS:
309
  hasta = (datetime.now() + timedelta(minutes=TIEMPO_BLOQUEO)).isoformat()
310
- c.execute("UPDATE login_attempts SET bloqueado_hasta=? WHERE username=%s", (hasta, username))
311
  conn.commit()
312
  conn.close()
313
 
@@ -348,7 +348,7 @@ def update_user_profile(username, gemini, tavily, email, enc_pass):
348
  c = conn.cursor()
349
  enc_gemini = crypto.encrypt_data(gemini) if gemini else ""
350
  enc_tavily = crypto.encrypt_data(tavily) if tavily else ""
351
- c.execute("UPDATE users SET gemini_key=?, tavily_key=?, email_user=?, email_pass_enc=? WHERE username=%s",
352
  (enc_gemini, enc_tavily, email, enc_pass, username))
353
  conn.commit()
354
  conn.close()
@@ -419,7 +419,7 @@ def insert_smart_inbox(licitacion, remitente, asunto, fecha, resumen, renglones,
419
  conn = get_connection()
420
  c = conn.cursor()
421
  c.execute(
422
- "INSERT INTO smart_inbox (licitacion, remitente, asunto, fecha, resumen, renglones_relacionados, cuerpo, borrador_respuesta) VALUES (%s, %s, %s, %s, ?, ?, ?, ?)",
423
  (licitacion, remitente, asunto, fecha, resumen, renglones, cuerpo, borrador))
424
  conn.commit()
425
  conn.close()
@@ -428,7 +428,7 @@ def insert_cotizacion(licitacion, renglon, proveedor, precio_unitario, moneda, t
428
  conn = get_connection()
429
  c = conn.cursor()
430
  c.execute(
431
- "INSERT INTO cotizaciones (licitacion, renglon, proveedor, precio_unitario, moneda, tiempo_entrega, condiciones, fecha, email_asunto) VALUES (%s, %s, %s, %s, ?, ?, ?, ?, ?)",
432
  (licitacion, renglon, proveedor, precio_unitario, moneda, tiempo_entrega, condiciones, fecha, email_asunto))
433
  conn.commit()
434
  conn.close()
@@ -436,7 +436,7 @@ def insert_cotizacion(licitacion, renglon, proveedor, precio_unitario, moneda, t
436
  def check_cotizacion_exists(licitacion, renglon, proveedor):
437
  conn = get_connection()
438
  c = conn.cursor()
439
- c.execute("SELECT id FROM cotizaciones WHERE licitacion=%s AND renglon=? AND proveedor=?",
440
  (licitacion, renglon, proveedor))
441
  exists = c.fetchone() is not None
442
  conn.close()
@@ -485,7 +485,7 @@ def crear_seguimiento(numero_licitacion, objeto, fecha_asignacion, fecha_envio_o
485
  c.execute("""INSERT INTO seguimiento_licitaciones
486
  (numero_licitacion, objeto, fecha_asignacion, fecha_envio_oferta,
487
  monto_ofertado, moneda, estado, link_sli, notas, responsable, fecha_registro)
488
- VALUES (%s, %s, %s, %s, ?, ?, 'En Preparacion', ?, ?, ?, ?)""",
489
  (numero_licitacion, objeto, fecha_asignacion, fecha_envio_oferta,
490
  monto_ofertado, moneda, link_sli, notas, responsable, fecha))
491
  conn.commit()
@@ -506,7 +506,7 @@ def actualizar_estado(licitacion_id, nuevo_estado, nota, registrado_por):
506
  conn = get_connection()
507
  c = conn.cursor()
508
  fecha = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
509
- c.execute("UPDATE seguimiento_licitaciones SET estado=? WHERE id=?", (nuevo_estado, licitacion_id))
510
  c.execute("""INSERT INTO seguimiento_historial (licitacion_id, fecha, estado_nuevo, nota, registrado_por)
511
  VALUES (%s, %s, %s, %s, %s)""", (licitacion_id, fecha, nuevo_estado, nota, registrado_por))
512
  conn.commit()
@@ -515,7 +515,7 @@ def actualizar_estado(licitacion_id, nuevo_estado, nota, registrado_por):
515
  def get_historial_seguimiento(licitacion_id):
516
  conn = get_connection()
517
  df = pd.read_sql_query(
518
- "SELECT fecha, estado_nuevo, nota, registrado_por FROM seguimiento_historial WHERE licitacion_id=? ORDER BY id DESC",
519
  conn, params=(licitacion_id,))
520
  conn.close()
521
  return df
@@ -523,8 +523,8 @@ def get_historial_seguimiento(licitacion_id):
523
  def eliminar_seguimiento(licitacion_id):
524
  conn = get_connection()
525
  c = conn.cursor()
526
- c.execute("DELETE FROM seguimiento_historial WHERE licitacion_id=?", (licitacion_id,))
527
- c.execute("DELETE FROM seguimiento_licitaciones WHERE id=?", (licitacion_id,))
528
  conn.commit()
529
  conn.close()
530
 
 
148
  if not c.fetchone():
149
  salt = bcrypt.gensalt()
150
  hashed_pw = bcrypt.hashpw(b"admin", salt).decode('utf-8')
151
+ c.execute("INSERT INTO users VALUES ('admin', %s, 'Gerencia', '', '', '', '')", (hashed_pw,))
152
 
153
  conn.commit()
154
  conn.close()
 
307
  intentos = c.fetchone()[0]
308
  if intentos >= MAX_INTENTOS:
309
  hasta = (datetime.now() + timedelta(minutes=TIEMPO_BLOQUEO)).isoformat()
310
+ c.execute("UPDATE login_attempts SET bloqueado_hasta=%s WHERE username=%s", (hasta, username))
311
  conn.commit()
312
  conn.close()
313
 
 
348
  c = conn.cursor()
349
  enc_gemini = crypto.encrypt_data(gemini) if gemini else ""
350
  enc_tavily = crypto.encrypt_data(tavily) if tavily else ""
351
+ c.execute("UPDATE users SET gemini_key=%s, tavily_key=%s, email_user=%s, email_pass_enc=%s WHERE username=%s",
352
  (enc_gemini, enc_tavily, email, enc_pass, username))
353
  conn.commit()
354
  conn.close()
 
419
  conn = get_connection()
420
  c = conn.cursor()
421
  c.execute(
422
+ "INSERT INTO smart_inbox (licitacion, remitente, asunto, fecha, resumen, renglones_relacionados, cuerpo, borrador_respuesta) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
423
  (licitacion, remitente, asunto, fecha, resumen, renglones, cuerpo, borrador))
424
  conn.commit()
425
  conn.close()
 
428
  conn = get_connection()
429
  c = conn.cursor()
430
  c.execute(
431
+ "INSERT INTO cotizaciones (licitacion, renglon, proveedor, precio_unitario, moneda, tiempo_entrega, condiciones, fecha, email_asunto) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
432
  (licitacion, renglon, proveedor, precio_unitario, moneda, tiempo_entrega, condiciones, fecha, email_asunto))
433
  conn.commit()
434
  conn.close()
 
436
  def check_cotizacion_exists(licitacion, renglon, proveedor):
437
  conn = get_connection()
438
  c = conn.cursor()
439
+ c.execute("SELECT id FROM cotizaciones WHERE licitacion=%s AND renglon=%s AND proveedor=%s",
440
  (licitacion, renglon, proveedor))
441
  exists = c.fetchone() is not None
442
  conn.close()
 
485
  c.execute("""INSERT INTO seguimiento_licitaciones
486
  (numero_licitacion, objeto, fecha_asignacion, fecha_envio_oferta,
487
  monto_ofertado, moneda, estado, link_sli, notas, responsable, fecha_registro)
488
+ VALUES (%s, %s, %s, %s, %s, %s, 'En Preparacion', %s, %s, %s, %s)""",
489
  (numero_licitacion, objeto, fecha_asignacion, fecha_envio_oferta,
490
  monto_ofertado, moneda, link_sli, notas, responsable, fecha))
491
  conn.commit()
 
506
  conn = get_connection()
507
  c = conn.cursor()
508
  fecha = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
509
+ c.execute("UPDATE seguimiento_licitaciones SET estado=%s WHERE id=%s", (nuevo_estado, licitacion_id))
510
  c.execute("""INSERT INTO seguimiento_historial (licitacion_id, fecha, estado_nuevo, nota, registrado_por)
511
  VALUES (%s, %s, %s, %s, %s)""", (licitacion_id, fecha, nuevo_estado, nota, registrado_por))
512
  conn.commit()
 
515
  def get_historial_seguimiento(licitacion_id):
516
  conn = get_connection()
517
  df = pd.read_sql_query(
518
+ "SELECT fecha, estado_nuevo, nota, registrado_por FROM seguimiento_historial WHERE licitacion_id=%s ORDER BY id DESC",
519
  conn, params=(licitacion_id,))
520
  conn.close()
521
  return df
 
523
  def eliminar_seguimiento(licitacion_id):
524
  conn = get_connection()
525
  c = conn.cursor()
526
+ c.execute("DELETE FROM seguimiento_historial WHERE licitacion_id=%s", (licitacion_id,))
527
+ c.execute("DELETE FROM seguimiento_licitaciones WHERE id=%s", (licitacion_id,))
528
  conn.commit()
529
  conn.close()
530