<reponame>Dopuu/scrap
import sqlite3
import os

arr = []
price = []
title = []
row = []


def create_database():
    c = sqlite3.connect("database.db")
    cursor = c.cursor()
    try:
        cursor.execute("""CREATE TABLE  products(
            title text,
            price float,
            image text
        )
        """)
        cursor.close()

    except sqlite3.Error as error:
        print(error)


def check_database():
    if not os.path.isfile("database.db"):
        create_database()


def main(title, price, image):
    create_database()
    try:
        c = sqlite3.connect("database.db")
        cursor = c.cursor()
        cursor.execute("INSERT INTO products VALUES(:title, :price, :image)",
                       {'title': title, 'price': float(price), 'image': f"static/pics/{image}"})
        c.commit()
    except:
        pass


def getLastRow():
    check_database()
    c = sqlite3.connect("database.db")
    cursor = c.cursor()
    last_row = cursor.execute('select * from products').fetchall()
    row.clear()
    row.append(last_row)
    arr.clear()
    title.clear()
    price.clear()
    for i in last_row:
        arr.append(i[2])
        title.append(i[0])
        price.append(i[1])


import sqlite3
import os

arr = []
price = []
title = []
row = []


def create_database():
    c = sqlite3.connect("database.db")
    cursor = c.cursor()
    try:
        cursor.execute("""CREATE TABLE  products(
            title text,
            price float,
            image text
        )
        """)
        cursor.close()

    except sqlite3.Error as error:
        print(error)


def check_database():
    if not os.path.isfile("database.db"):
        create_database()


def main(title, price, image):
    create_database()
    try:
        c = sqlite3.connect("database.db")
        cursor = c.cursor()
        cursor.execute("INSERT INTO products VALUES(:title, :price, :image)",
                       {'title': title, 'price': float(price), 'image': f"static/pics/{image}"})
        c.commit()
    except:
        pass


def getLastRow():
    check_database()
    c = sqlite3.connect("database.db")
    cursor = c.cursor()
    last_row = cursor.execute('select * from products').fetchall()
    row.clear()
    row.append(last_row)
    arr.clear()
    title.clear()
    price.clear()
    for i in last_row:
        arr.append(i[2])
        title.append(i[0])
        price.append(i[1])
CREATE TABLE  products(
             title text,
             price float,
             image text
         )