def items_available_to_buy(value_tuple): try: filter_3 = "" filter_4 = "" filter_5 = "" filter_6 = "" if value_tuple[3] != "": filter_3 = " and prize = '" + value_tuple[3] + "'" if value_tuple[4] != "": filter_4 = " and colour = '" + value_tuple[4] + "'" if value_tuple[5] != "": filter_5 = " and brand = '" + value_tuple[5] + "'" DISPLAYING_FORMULA = "SELECT item_type , gender , size , prize , colour , brand FROM inventory WHERE item_type = '" + value_tuple[ 0] + "' and gender = '" + value_tuple[ 1] + "' and size = '" + value_tuple[ 2] + "'" + filter_3 + filter_4 + filter_5 mycursor.execute(DISPLAYING_FORMULA) data = mycursor.fetchall() return data except: bf.easy_center_align( "Sorry an error occured in finding the items available to buy")
def get_full_values_of_item(value_tuple): """THIS functions completes the value of the tuple from the unique item and returns the full tuple""" try: list_1 = list(value_tuple) list_2 = list_1 data = items_available_to_buy(value_tuple) if list_1[0] == "": list_2[0] = data[0][0] if list_1[1] == "": list_2[1] = data[0][1] if list_1[2] == "": list_2[2] = data[0][2] if list_1[3] == "": list_2[3] = data[0][3] if list_1[4] == "": list_2[4] = data[0][4] if list_1[5] == "": list_2[5] = data[0][5] #list_2.append(list_1[6]) final_tuple = tuple(list_2) return final_tuple except: bf.easy_center_align( "Sorry an error occured in getting the full values.")
def start_as_user(u_name): try: global username username = u_name """Start as user/customer""" #user_name is the name of the user create_profile(username) udb.create_cart(username) Username = username[0].upper() + username[1:] bf.easy_center_align("Started as " + Username) bf.hanprt("Now you can ask me anything") bf.handler = "Staff" #the handler from basic function #try: u_input = bf.ask_input() while(1): if ((u_input == "i am done") or (u_input == "exit") or (u_input == "leave") or (u_input == "close")): bf.hanprt("Thanks for visiting ," + username) udb.delete_cart(username) break display_u_output(process_u_input(bf.scan_r(u_kwd_act , u_input),u_input)) u_input = bf.ask_input() except: bf.hanprt("Sorry an error occured in starting as user") ask.username()
def delete_cart(username): """This function creates the table as cart""" #bf.nnprt("Shopping cart deleted") try: formula = "DROP TABLE " + username + "_cart " mycursor.execute(formula) mycon.commit() except: bf.easy_center_align( "Sorry an error occured as there is no cart to delete")
def create_profile_table(username): """Creating user profile""" try: formula = "CREATE TABLE " + username + "_profile (item_type VARCHAR(100) , gender CHAR(1) , size CHAR(4) , prize DECIMAL , colour VARCHAR(20) , brand VARCHAR(100) , quantity INTEGER , amount DECIMAL , payment_mod VARCHAR(20) , date DATETIME )" mycursor.execute(formula) mycon.commit() bf.easy_center_align("New profile created.") except: #bf.hanprt("Sorry an error occured in creating the profile table") pass
def data_of_cart(username): """This functions returns the list of items present in the cart""" try: DISPLAYING_FORMULA = "SELECT * FROM " + username + "_cart" #Fbf.nnprt(DISPLAYING_FORMULA) #del #bf.nnprt(value_tuple)#del mycursor.execute(DISPLAYING_FORMULA) data = mycursor.fetchall() # mycursor.commit() return data except: bf.easy_center_align("Sorry an error occured as there is no cart")
def display_profile(item_list): """THis function displays the user profile""" try: if item_list != []: bf.random_pr_string( ("Your customer loves these", "History of the user", "Profile ", "Showing the profile")) bf.nnprt("") #bf.line("_",130) bf.nnprt(bf.center_align("_", 149)) #bf.nnprt("|___ITEM____|__GENDER__|__SIZE___|____PRIZE__|_COLOUR_|__BRAND_|__QUANTY_|___AMOUNT___|__PAYMENT_MOD__|__DATE_AND_TIME____|") bf.nnprt("|__" + bf.left_align("ITEM", 10).upper() + "|__" + bf.left_align("gender", 7).upper() + "|__" + bf.left_align("SIZE", 7).upper() + "|__" + bf.left_align("PRIZE", 13).upper() + "|__" + bf.left_align("COLOUR", 10).upper() + "|__" + bf.left_align("BRAND", 15).upper() + "|__" + bf.left_align("QUANTITY", 10).upper() + "|__" + bf.left_align("AMOUNT", 13).upper() + "|__" + bf.left_align("PAYMENT_MOD", 12).upper() + "|__" + bf.left_align("DATE AND TIME", 20).upper() + "|") for i in item_list: p = str(i[3]) q = str(i[6]) a = str(i[7]) d = str(i[9]) #print(d) #bf.easy_center_align( q + "pcs. of " + i[0] + " of brand " + i[5].upper() + " of size " +i[2].upper() + " of colour " + i[4].upper() + " of prize Rs." + p + "/-") bf.nnprt("|__" + bf.left_align(i[0], 10).upper() + "|__" + bf.left_align(i[1], 7).upper() + "|__" + bf.left_align(i[2], 7).upper() + "|__Rs." + bf.left_align(p, 10).upper() + "|__" + bf.left_align(i[4], 10).upper() + "|__" + bf.left_align(i[5], 15).upper() + "|__" + bf.left_align(q, 10).upper() + "|__Rs." + bf.left_align(a, 10).upper() + "|__" + bf.left_align(i[8], 12).upper() + "|__" + bf.left_align(d, 20).upper() + "|") #bf.line("_",130) bf.nnprt(bf.center_align("_", 149)) bf.nnprt("") else: bf.hanprt("No History available") except: bf.easy_center_align("Sorry an error occured displaying the profile")
def add_to_cart(value_tuple, username): """This function - the items selected by the user to the cart""" try: if value_tuple == (): #bf.hanprt("Sorry you have not asked me of anything to buy") #bf.hanprt("Try saying like 'I want to buy'") pass else: value_tuple = (get_full_values_of_item(value_tuple)) p = str(value_tuple[3]) check_quantity_formula = "SELECT quantity FROM inventory WHERE item_type = '" + value_tuple[ 0] + "' and gender = '" + value_tuple[ 1] + "' and size = '" + value_tuple[ 2] + "'and prize = '" + p + "' and colour = '" + value_tuple[ 4] + "' and brand = '" + value_tuple[5] + "'" mycursor.execute(check_quantity_formula) data = mycursor.fetchall() quantity_available = int(data[0][0]) quantity_needed = int(value_tuple[6]) if (quantity_needed <= quantity_available): final_list = [] final_list.append(value_tuple[0]) final_list.append(value_tuple[1]) final_list.append(value_tuple[2]) final_list.append(p) final_list.append(value_tuple[4]) final_list.append(value_tuple[5]) final_list.append(quantity_needed) amount = int(p) * int(quantity_needed) final_list.append(amount) final_tuple = tuple(final_list) INSERT_TO_cart = "INSERT INTO " + username + "_cart (item_type , gender , size , prize , colour , brand , quantity , amount) VALUES (%s ,%s , %s , %s , %s , %s , %s ,%s)" mycursor.execute(INSERT_TO_cart, final_tuple) mycon.commit() bf.random_pr_string(("Added to cart", "New Item added", "Item added to cart", "Added", "Done")) else: bf.hanprt( "Sorry , we don't have this much quantity available right now the maxinum quantity you can get is " + str(quantity_available)) except: bf.easy_center_align("Sorry an error occured in adding to cart")
def create_cart(username): """This function creates the table as cart""" #bf.nnprt("Shopping cart created") try: if (bool((check_table(str(username + "_cart"))))): bf.hanprt( "It seem you once visited here so starting with your old cart") else: formula = "CREATE TABLE " + username + "_cart (item_type VARCHAR(100) , gender CHAR(1) , size CHAR(4) , prize DECIMAL , colour VARCHAR(20) , brand VARCHAR(100) , quantity INTEGER , amount DECIMAL )" mycursor.execute(formula) mycon.commit() bf.easy_center_align("New cart created") except: bf.easy_center_align( "Sorry an error occured.Please run the program again as your input is not valid for smooth functioning" )
def display_stocks(item_list): try: if item_list != []: bf.random_pr_string(( "This is what we have", "We have these", "This is the stock", "Stock available with us", "Items we have", "Available stock", )) bf.line("_", 90) bf.center_align("_", 20) #bf.nnprt("|___ITEM____|__GENDER__|__SIZE___|____PRIZE__|_COLOUR_|__BRAND_|__QUANTY_|") bf.nnprt(("|__" + bf.left_align("ITEM", 10).upper() + "|__" + bf.left_align("gender", 7).upper() + "|__" + bf.left_align("SIZE", 7).upper() + "|__" + bf.left_align("PRIZE", 10).upper() + "|__" + bf.left_align("COLOUR", 10).upper() + "|__" + bf.left_align("BRAND", 15).upper() + "|__" + bf.left_align("QUANTITY", 10) + "|")) for i in item_list: p = str(i[3]) q = str(i[6]) #bf.easy_center_align( q + "pcs. of " + i[0] + " of brand " + i[5].upper() + " of size " +i[2].upper() + " of colour " + i[4].upper() + " of prize Rs." + p + "/-") bf.nnprt("|__" + bf.left_align(i[0], 10).upper() + "|__" + bf.left_align(i[1], 7).upper() + "|__" + bf.left_align(i[2], 7).upper() + "|__Rs." + bf.left_align(p, 7).upper() + "|__" + bf.left_align(i[4], 10).upper() + "|__" + bf.left_align(i[5], 15).upper() + "|__" + bf.left_align(q, 10).upper() + "|") bf.line("_", 90) bf.nnprt("") else: bf.hanprt("No Item available in the stocks") except: bf.easy_center_align( "Sorry an error occured in finding whats in the stock")
def showcase_designs(item_list): try: if item_list != []: bf.random_pr_string(("Here are some beautiful designs for you" , "You may like these designs" , "I am sure you will love them" , "Please have a look to them", "These designs are awesome" , "Try these" ,)) for i in item_list: p = str(i[3]) bf.easy_center_align("A " + i[0] + " of brand " + i[5].upper() + " of size " +i[2].upper() + " of colour " + i[4].upper() + " of prize Rs." + p + "/-") else: bf.hanprt("Sorry sir we don't have this item available at this moment") except: bf.hanprt("Sorry an error occured in showcasing what to buy")
def print_cart(item_list): try: """This function prints the cart""" if item_list != []: bf.random_pr_string(("You have selected " , "This is what you have selected" , "Your cart contains" , "Items you have added" ,)) for i in item_list: p = str(i[3]) q = str(i[6]) a = str(i[7]) bf.easy_center_align(q +"pcs of " + i[0] + "("+i[1].upper()+") of brand " + i[5].upper() + " of size " +i[2].upper() + " of colour " + i[4].upper() + " of prize Rs." + p + "/-. Amount Rs." + a + "/-") else: bf.hanprt("Your cart is empty you have not added anything to your cart") except: bf.hanprt("Sorry an error occured in printing the cart")
def start_as_owner(): try: username = "******" bf.handler = "Auto K.B." bf.easy_center_align("Started as owner") bf.hanprt("Now you can start.") o_input = bf.ask_input() while (1): if ((o_input == "i am done") or (o_input == "exit") or (o_input == "leave") or (o_input == "quit")): bf.hanprt("Thanks for visiting," + username) break display_o_output( process_o_input(bf.scan_r(o_kwd_act, o_input), o_input)) o_input = bf.ask_input() except: bf.easy_center_align("Sorry an error occured in starting as owner") start_as_owner()
def show_stocks(value_tuple): try: filter_0 = "" filter_1 = "" filter_2 = "" filter_3 = "" filter_4 = "" filter_5 = "" filter_6 = "" additional_statement = "" #where clause if value_tuple[0] != "": filter_0 = "item_type = '" + value_tuple[0] + "' and " if value_tuple[1] != "": filter_1 = "gender = '" + value_tuple[1] + "' and " if value_tuple[2] != "": filter_2 = "size = '" + value_tuple[2] + "' and " if value_tuple[3] != "": filter_3 = "prize = '" + value_tuple[3] + "' and " if value_tuple[4] != "": filter_4 = "colour = '" + value_tuple[4] + "' and " if value_tuple[5] != "": filter_5 = "brand = '" + value_tuple[5] + "' and " if value_tuple[6] != "": filter_6 = "quantity = '" + value_tuple[6] + "' and " if ((value_tuple[0] != "") or (value_tuple[1] != "") or (value_tuple[2] != "") or (value_tuple[3] != "") or (value_tuple[4] != "") or (value_tuple[5] != "") or (value_tuple[6] != "")): additional_statement = "WHERE " DISPLAYING_FORMULA = "SELECT * FROM inventory " + additional_statement + filter_0 + filter_1 + filter_2 + filter_3 + filter_4 + filter_5 + filter_6 d = DISPLAYING_FORMULA[0:-4] mycursor.execute(d) data = mycursor.fetchall() # mycursor.commit() return data except: bf.easy_center_align("Sorry an error occured in displaying stocks")
def add_entire_stock(value_tuple): """Add entire stocks completely whole row bf.nnprt(value_tuple) bf.nnprt(type(value_tuple[0])) bf.nnprt(type(value_tuple[1])) bf.nnprt(type(value_tuple[2])) bf.nnprt(type(value_tuple[3])) bf.nnprt(type(value_tuple[4])) bf.nnprt(type(value_tuple[5])) bf.nnprt(type(value_tuple[6])) bf.nnprt(type(value_tuple)) """ try: mycursor.execute(INSERTION_FORMULA, value_tuple) #mycursor.commit() bf.random_pr_string(("New stock added successfully", "New stock added", "Stock added", "Done")) # mycursor.execute("INSERT INTO inventory (item_type , gender , size , prize , colour , brand , quantity) VALUES ((jean, m, 'm , 800 , blue , gucci , 4 ))") mycon.commit() #bf.nnprt(item_type , gender , size , prize , colour , brand , quantity) except: bf.easy_center_align("Sorry an error occured in adding entire stock")
def ask_payment_mod(): try: bf.hanprt("Which payment method will suit you") payment_mod = bf.ask_input() if( (re.search(r" cash "," " + payment_mod + " ")) or (re.search(r" card "," " + payment_mod + " ")) or (re.search(r" cheque "," " + payment_mod + " ")) or (re.search(r" e(-| )wallet "," " + payment_mod + " ")) ): if ( (re.search(r" boy(s)? "," " + payment_mod + " ")) ): payment_mod = "cash" elif ( (re.search(r" card "," " + payment_mod + " ")) ): payment_mod = "card" elif ((re.search(r" cheque "," " + payment_mod + " ")) ): payment_mod = "cheque" elif ((re.search(r" e(-| )wallet "," " + payment_mod + " ")) ): payment_mod = "ewallet" return payment_mod else: bf.hanprt("Invalid option , Please try again (cash/card/e-wallet/cheque)") return ask_payment_mod() except: bf.easy_center_align("Sorry an error occured.Please try again") ask_payment_mod()
def ask_entire_stock(value_tuple): """Asks the entire stocks and stores the values and asks the user for incomplete values if empty values is provided""" try: value_list = list(value_tuple) if value_tuple[0] == "": value_list[0] = bf.ask_item_type() if value_tuple[1] == "": value_list[1] = bf.ask_gender() if value_tuple[2] == "": value_list[2] = bf.ask_size() if value_tuple[3] == "": value_list[3] = bf.ask_prize() if value_tuple[4] == "": value_list[4] = bf.ask_colour() if value_tuple[5] == "": value_list[5] = bf.ask_brand() if value_tuple[6] == "": value_list[6] = bf.ask_quantity() value_tuple_2 = tuple(value_list) return value_tuple_2 except: bf.easy_center_align("Sorry an error occured in asking the stock") ask_entire_stock()
DB_PASS = "******" try: #searching for the old database mycon = sqltor.connect(host="localhost", user="******", port=3306, passwd=DB_PASS, database="autokb") #bf.easy_center_align("Started with the Auto K.B. Database") mycursor = mycon.cursor() except: #there is no databse creating a new one now bf.easy_center_align("Could not connect with database please try again ") """ if mycon.is_connected(): bf.easy_center_align("Connection established succesfully") """ #mycon.close() #bf.nnprt(item_type , gender , size , prize , colour , brand , quantity) def items_available_to_buy(value_tuple): try: filter_3 = "" filter_4 = "" filter_5 = ""
def items_available_to_remove(value_tuple, username): try: """filter_3 = "" filter_4 = "" filter_5 = "" filter_6 = "" if value_tuple[3] != "": filter_3 = " and prize = '" + value_tuple[3]+ "'" elif value_tuple[4] != "": filter_4 = " and colour = '" + value_tuple[4] + "'" elif value_tuple[5] != "": filter_5 = " and brand = '" + value_tuple[5] + " #DISPLAYING_FORMULA = "SELECT item_type , gender , size , prize , colour , brand FROM "+username+"_cart WHERE item_type = '" + value_tuple[0] + "' and gender = '" + value_tuple[1] + "' and size = '" + value_tuple[2] + "'"+ filter_3 +filter_4 + filter_5 DISPLAYING_FORMULA = "SELECT * FROM "+username+"_cart" mycursor.execute(DISPLAYING_FORMULA ) data = mycursor.fetchall() print(data) return data""" filter_0 = "" filter_1 = "" filter_2 = "" filter_3 = "" filter_4 = "" filter_5 = "" filter_6 = "" additional_statement = "" #where clause if value_tuple[0] != "": filter_0 = "item_type = '" + value_tuple[0] + "' and " if value_tuple[1] != "": filter_1 = "gender = '" + value_tuple[1] + "' and " if value_tuple[2] != "": filter_2 = "size = '" + value_tuple[2] + "' and " if value_tuple[3] != "": filter_3 = "prize = '" + value_tuple[3] + "' and " if value_tuple[4] != "": filter_4 = "colour = '" + value_tuple[4] + "' and " if value_tuple[5] != "": filter_5 = "brand = '" + value_tuple[5] + "' and " if value_tuple[6] != "": filter_6 = "quantity = '" + value_tuple[6] + "' and " if ((value_tuple[0] != "") or (value_tuple[1] != "") or (value_tuple[2] != "") or (value_tuple[3] != "") or (value_tuple[4] != "") or (value_tuple[5] != "") or (value_tuple[6] != "")): additional_statement = "WHERE " DISPLAYING_FORMULA = "SELECT * FROM " + username + "_cart " + additional_statement + filter_0 + filter_1 + filter_2 + filter_3 + filter_4 + filter_5 + filter_6 d = DISPLAYING_FORMULA[0:-4] mycursor.execute(d) data = mycursor.fetchall() return data except: bf.easy_center_align( "Sorry an error occured in finding the items available to buy")
try: #searching for the old database mycon = sqltor.connect(host="localhost", user="******", port=3306, passwd=DB_PASS, database="autokb") #bf.easy_center_align("Started with the old database") mycursor = mycon.cursor() except: #there is no databse creating a new one now mycon = sqltor.connect(host="localhost", user="******", passwd=DB_PASS) bf.easy_center_align("Old database was not found creating a new one") mycursor = mycon.cursor() mycursor.execute("CREATE DATABASE autokb") bf.easy_center_align("Database autokb created successfully") #mycursor.execute("USE DATABASE autokb4") mycon.close() mycon = sqltor.connect(host="localhost", user="******", port=3306, passwd=DB_PASS, database="autokb") mycursor = mycon.cursor()