Esempio n. 1
0
    def find_substitute(self):
        """
            This method is the client for the application
        """
        # Ask the user to choose a category
        menu_title = 'Choisissez une catégorie'
        answers_title = 'Sélectionnez une catégorie (numéro)'
        answers = API_CATEGORIES

        category = SelectionMenu(menu_title, answers_title, answers)

        # Ask user to choose a product to substitute
        to_substitute = None

        while not to_substitute:
            # Display available products in the chossen category
            available_products = self.database.select_products(
                category.selected, NUMBER_OF_PRODUCTS,
                DISCRIMINANT_NUTRISCORE_GRADE)
            available_products.append('Afficher d\'autres produits au hasard')
            menu_title = 'Choisissez un produit à subsituer'
            answers_title = 'Sélectionnez un produit (numéro)'
            answers = available_products

            product = SelectionMenu(menu_title, answers_title, answers)

            if product.selected != 'Afficher d\'autres produits au hasard':
                to_substitute = Product(
                    **self.database.select_product(product.selected))

        # Select in the database the potential substitutes for to the selected
        # product
        available_substitutes = self.database.select_substitutes(
            to_substitute, NUMBER_OF_SIMILAR_CATEGORIES, NUMBER_OF_SUBSTITUTES)

        if available_substitutes:
            # Ask the user to choose a substitute
            menu_title = 'Choisissez un substitut'
            answers_title = 'Sélectionner un substitut (numéro)'
            answers = available_substitutes

            substitute = SelectionMenu(menu_title, answers_title, answers)

            substituted = Product(
                **self.database.select_product(substitute.selected))
            substituted.display()
        else:
            print('Nous n\'avons pas de substitut à vous proposer.')
            substituted = None

        if substituted:
            # Ask the user if she·he wants to save the product
            menu_title = 'Souhaitez-vous sauvegarder le produit ?'
            answers_title = 'Sélectionnez une réponse (numéro)'
            answers = ['Oui', 'Non']

            save = SelectionMenu(menu_title, answers_title, answers)

            if save.selected == 'Oui':
                self.database.save_product(to_substitute, substituted)
Esempio n. 2
0
    def find_saved(self):
        """
            This method display the products already saved by the user
        """
        # Get all products saved in the database
        saved_products = self.database.select_saved_products()

        if saved_products:
            # Ask the user which product she·he wants to read
            menu_title = 'Quel substitut souhaitez-vous consulter ?'
            answers_title = 'Sélectionnez le substitut (numéro)'
            answers = saved_products

            substituted = SelectionMenu(menu_title, answers_title, answers)
        else:
            print('Aucun substitut n\'a était sauvegardé pour l\'instant')
            substituted = None

        if substituted:
            # Display the selected subsitute
            product = Product(
                **self.database.select_product(substituted.selected))
            product.display()