Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created July 2, 2019 23:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/871e680bf2d945a5b0f7cfcc3180925a to your computer and use it in GitHub Desktop.
Save parzibyte/871e680bf2d945a5b0f7cfcc3180925a to your computer and use it in GitHub Desktop.
import sqlite3
try:
bd = sqlite3.connect("libros.db")
cursor = bd.cursor()
busqueda = input("Escribe tu búsqueda: ")
if not busqueda:
print("Búsqueda inválida")
exit()
sentencia = "SELECT * FROM libros WHERE titulo LIKE ?;"
cursor.execute(sentencia, [ "%{}%".format(busqueda) ])
libros = cursor.fetchall()
print("+{:-<20}+{:-<20}+{:-<10}+{:-<50}+".format("", "", "", ""))
print("|{:^20}|{:^20}|{:^10}|{:^50}|".format("Autor", "Género", "Precio", "Título"))
print("+{:-<20}+{:-<20}+{:-<10}+{:-<50}+".format("", "", "", ""))
for autor, genero, precio, titulo in libros:
print("|{:^20}|{:^20}|{:^10}|{:^50}|".format(autor, genero, precio, titulo))
print("+{:-<20}+{:-<20}+{:-<10}+{:-<50}+".format("", "", "", ""))
except sqlite3.OperationalError as error:
print("Error al abrir:", error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment