def account():
    t = current_user.retuser()
    data = db.execute(
        "SELECT bookname FROM userscart WHERE username=:username", {"username": t}
    ).fetchall()
    print(data)
    today = date.today()
    # print(today)
    l2 = request.args.get(
        "my_var1"
    )  # get request with variable name to issue book l2 is the name of the book to issue
    rec = db.execute(
        "SELECT bookname FROM issue WHERE bookname=:bookname AND username=:username",
        {"bookname": l2, "username": t},
    ).fetchone()
    count = db.execute(
        "SELECT count(bookname) FROM issue WHERE username=:username", {"username": t}
    ).fetchone()
    if count[0] > 3:
        flash("you are not allowed to issue more than four book", "danger")
        return redirect("/account")
    elif rec == None and l2 != None:
        db.execute(
            "INSERT INTO issue(username,issuedate,bookname) VALUES(:username,:issuedate,:bookname)",
            {"username": t, "issuedate": today, "bookname": l2},
        )
        db.execute(
            "UPDATE book SET quantity = quantity-1 WHERE bookname=:search",
            {"search": l2},
        )
        # db.execute()
        db.commit()
    data1 = db.execute(
        "SELECT bookname FROM userscart WHERE bookname=:bookname", {"bookname": l2}
    ).fetchone()
    if data != None and rec != None:
        db.execute("DELETE FROM userscart WHERE bookname=:bookname", {"bookname": l2})
        db.commit()
    data1 = db.execute(
        "SELECT bookname FROM issue WHERE username=:username", {"username": t}
    ).fetchall()

    ret_book = request.args.get(
        "my_var2"
    )  # get request with var name to return book ret_book contains the name of the book to return

    if ret_book != None:
        db.execute(
            "DELETE FROM issue WHERE username=:username AND bookname=:bookname",
            {"username": t, "bookname": ret_book},
        )
        db.execute(
            "UPDATE book SET quantity = quantity+1 WHERE bookname=:search",
            {"search": ret_book},
        )
        db.commit()
        # return redirect('/account')
    return render_template("account.html", data=data, data1=data1)
def CN():
    loggedin_user = current_user.retuser()
    l = request.args.get("my_var")
    if l != None:
        rec = db.execute(
            "SELECT bookname FROM userscart WHERE bookname=:bookname", {"bookname": l}
        ).fetchone()
        if rec == None:
            db.execute(
                "INSERT INTO userscart(bookname,username) VALUES(:bookname,:username)",
                {"bookname": l, "username": loggedin_user},
            )
            db.commit()
    bookid = db.execute(
        "SELECT serial_no FROM book WHERE bookname=:bookname", {"bookname": "CN"}
    ).fetchone()
    info = process("CN", bookid, loggedin_user)
    return render_template("CN.html", info=info)
def alchemy():
    loggedin_user = current_user.retuser()
    l = request.args.get("my_var")  # var l deals only with cart and issue
    if l != None:
        rec = db.execute(
            "SELECT bookname FROM userscart WHERE bookname=:bookname", {"bookname": l}
        ).fetchone()
        if rec == None:
            db.execute(
                "INSERT INTO userscart(bookname,username) VALUES(:bookname,:username)",
                {"bookname": l, "username": loggedin_user},
            )
            db.commit()
    bookid = db.execute(
        "SELECT serial_no FROM book WHERE bookname=:bookname", {"bookname": "alchemyst"}
    ).fetchone()
    # db.execute("UPDATE bookcount SET bookcount=bookcount+1 WHERE bookname==:ab",ab=b)
    # db.execute("UPDATE book_cout1 SET alchemyst = alchemyst+1 ")
    info = process("alchemyst", bookid, loggedin_user)
    return render_template("alchemyst.html", info=info)