예제 #1
0
파일: asker.py 프로젝트: Gotha01/Project-5
 def display_favorite(self):
     system("cls")
     all_fav = Favourites.display_all_favourite_product()
     element_to_search = {}
     if all_fav != []:
         for element in all_fav:
             element_to_search[element[0]] = element[1]
             C_EMPTY.append(
                 Product.display_product(["name_product"], "id_product",
                                         element[0])[0][0])
         C_EMPTY.append(MAIN_MENU)
         C_EMPTY.append(SUPRESS)
         qst_all_fav = Question(QUESTIONER, Q5, clean=1).answer
         if qst_all_fav != SUPRESS and qst_all_fav != MAIN_MENU:
             favourite_prod = Product.display_product(["id_product"],
                                                      "name_product",
                                                      qst_all_fav)[0][0]
             Favourites.display_favourite_product(
                 str(favourite_prod),
                 str(element_to_search[favourite_prod]))
             all_fav.clear()
             C_EMPTY.clear()
         elif qst_all_fav == SUPRESS:
             Favourites.suppress_all()
             all_fav.clear()
             C_EMPTY.clear()
             return MAIN_MENU
         elif qst_all_fav == MAIN_MENU:
             C_EMPTY.clear()
             return MAIN_MENU
     else:
         Question(display(150, "=", NO_FAV_PRODUCT, 1, "|", "left"),
                  clean=1)
     return MAIN_MENU
예제 #2
0
파일: asker.py 프로젝트: Gotha01/Project-5
 def search_product_to_replace(self):
     #Function to find products by name
     correct_product = True
     while correct_product:
         product_to_replace = Question(display(150, "=", REPLACE_PROD, 2,
                                               "|", "left"),
                                       clean=1).answer
         if len(product_to_replace) >= 3:
             prod_find = Product.display_product(
                 ["name_product, nutrition_grades_product"], 'name_product',
                 "%" + product_to_replace + "%")
             if prod_find != []:
                 for element in prod_find:
                     C_EMPTY.append(element[0] + " (" + element[1] + ")")
                 C_EMPTY.append(MAIN_MENU)
                 favourite_prod = Question(QUESTIONER, Q5, clean=1).answer
                 if favourite_prod != MAIN_MENU:
                     choiced_product = Product.display_product(
                         ["*"], "name_product", favourite_prod[0:-4])[0]
                     self.display_details(choiced_product)
                     ids = self.ask_found_better(str(choiced_product[2]))
                     if ids != MAIN_MENU:
                         rec = self.ask_add_favourite(
                             ids, choiced_product[0])
                         return MAIN_MENU
                     else:
                         return MAIN_MENU
                 else:
                     return MAIN_MENU
             else:
                 no_product = Question(QUESTIONER, Q7, clean=1).answer
                 if no_product == "Réessayer.":
                     continue
                 else:
                     return no_product
         else:
             system("cls")
             input(display(150, "=", SEARCHING_RULE, 2, "|"))
예제 #3
0
파일: asker.py 프로젝트: Gotha01/Project-5
 def ask_found_better(self, category_id):
     #Function to suggest finding a better product.
     better_prod = Question(QUESTIONER, Q6, clean=1).answer
     if better_prod == "Oui.":
         C_EMPTY.clear()
         prod_search = Product.display_product(
             ["name_product", "id_product", "nutrition_grades_product"],
             "category_ID",
             category_id[0],
             order_by="nutrition_grades_product",
             numlimit="5")
         product_and_grade = []
         for found_prod in prod_search:
             product_and_grade.append(found_prod[0] + " (" + found_prod[2] +
                                      ")")
             C_EMPTY.append(product_and_grade[-1])
         fav_prod = Question(QUESTIONER, Q6_1, clean=1).answer
         fav_prod_details = Product.display_product(["*"], "name_product",
                                                    fav_prod[0:-4])[0]
         self.display_details(fav_prod_details)
         C_EMPTY.clear()
         return fav_prod_details[0]
     else:
         return MAIN_MENU
예제 #4
0
파일: asker.py 프로젝트: Gotha01/Project-5
 def search_products_like_category(self):
     #Function to find products by category
     cat_prod_dict = {}
     category_to_check = self.answer.lower().replace(".", "")
     category_id = Categories.read_column_sql(
         "id", f"WHERE name='{category_to_check}'")
     cat_products = Product.display_product(
         ["name_product", "id_product", "nutrition_grades_product"],
         'category_ID', category_id[0])
     product_and_grade = []
     for element in cat_products:
         cat_prod_dict[element[0]] = [element[1], element[2]]
         product_and_grade.append(element[0] + " (" + element[2] + ")")
         C_EMPTY.append(product_and_grade[-1])
     first_question = Question(QUESTIONER, Q3_1, clean=1).answer
     choiced_product = Product.display_product(
         ["*"], "id_product",
         f"{cat_prod_dict[first_question[0:-4]][0]}")[0]
     C_EMPTY.clear()
     self.display_details(choiced_product)
     ids = self.ask_found_better(category_id)
     if ids != MAIN_MENU:
         self.ask_add_favourite(ids, choiced_product[0])
     return MAIN_MENU