Example #1
0
class Command:
    """Allows to follow user's path"""
    def __init__(self):
        self.database = Db()
        self.control = Control()

    def cli(self):
        Display.greeting()
        continu = True

        while continu:
            substitutes = self.database.get_substitute()
            self.control.substitution(substitutes)
            records_cat = self.database.get_infos_category()
            Display.display_categories(records_cat)
            choice = self.control.check_input(
                "\nChoose the index of one of the categories:",
                records_cat,
            )
            records_prod = self.database.get_infos_product(choice)
            records_prod_cleaned = ProductsCleaned().clean(records_prod)
            sampling = Display.display_category_product(
                choice, records_cat, records_prod_cleaned)
            choice_prod = self.control.check_input(
                "\nChoose the index of one of the products:",
                sampling,
            )
            records_prod = Display.display_products(choice_prod,
                                                    records_prod_cleaned)
            choice_subs = self.control.check_input(
                "\nChoose the index of a product to substitute: ",
                records_prod,
            )
            selec = [(1, 1), (2, 2)]
            choice = self.control.check_input(
                "\nDo you want to register this substitute "
                "in the database?\n\n1:no\n2:yes\n\nYour answer: ",
                selec,
            )
            if choice == 2:
                self.database.update_data(choice_prod, choice_subs)
            else:
                pass
            choice = self.control.check_input(
                "\nDo you want to search other products?"
                "\n\n1:no\n2:yes\n\nYour answer: ",
                selec,
            )
            if choice == 1:
                self.database.cursor.close()
                break