Esempio n. 1
0
    def remove_word(self, forever=False):

        # Volver si no hay palabras que retirar
        if (forever and not self.pal_data) or (not forever
                                               and not self.pal_user):
            input("There's no words... ")
            print()
            return

        print(
            'Please write the numbers separating by commas the words that do you want remove:\n'
            '(Example: 1,2,5,...)\n')

        if forever:
            print(
                'This option also will be in the words of your custom lesson...\n'
            )
            dict_list_pal = my_sort.date(self.pal_data)
        else:
            dict_list_pal = my_sort.date(
                my_converter.List_toDict(self.pal_user, self.pal_data))

        my_print.show_list_words(dict_list_pal)
        user_petition = input('Option(s): ')

        if ':' in user_petition:
            pos = user_petition.index(':')
            num_first = int(user_petition[:pos])
            num_last = int(user_petition[pos + 1:]) + 1
            user_petition = [n for n in range(num_first, num_last)]

        else:
            user_petition = user_petition.split(',')
            user_petition = [int(n) for n in user_petition]

        for n in user_petition:
            pal = dict_list_pal[n]
            pal = self.pal_data[pal]

            if forever:
                # Eliminamos el archivo de sonido
                try:
                    for name_file in pal['Sound']:
                        os.remove(name_file)
                except KeyError:
                    pass

                # Eliminamos la palabra de DATA
                del self.pal_data[pal['Word']]

            try:
                self.pal_user.remove(pal['Word'])
            except ValueError:
                pass
        jsonReader.dictToJson(PATH_DATA, self.pal_data)
        jsonReader.dictToJson(PATH_USER_LESSON, self.pal_user)

        my_print.message_press_any_btn(True)
        return
Esempio n. 2
0
    def show_data(self):
        print('DATA words:\n')

        dict_list_pal = my_sort.date(self.pal_data)
        my_print.show_list_words(dict_list_pal)

        my_print.message_press_any_btn()
        return
Esempio n. 3
0
    def modify_word(self):
        print('Modify the attributes about some word\n')

        dict_list_pal = my_sort.date(self.pal_data)
        my_print.show_list_words(dict_list_pal)

        print('Please choice some word that do you want to modify')
        user_num = int(input('option: '))

        pal = dict_list_pal[user_num]
        pal_like_dict = self.pal_data[pal]

        self.show_word(pal_like_dict)

        while True:
            print("What attribute do you want change?\n"
                  "     1) Word\n"
                  "     2) Definition\n"
                  "     3) Translation\n"
                  "     4) Example\n"
                  "     5) Back <--")

            user_option = input('option: ')
            print()
            
            if user_option == "5":
                return

            if user_option == "1":
                print("Notice!, you must find this word in the file DATA.json and USER_LESSON.json in the "
                    "folder 'content' and apply the change there...")
                input()
                return

            elif user_option == "2":
                print("last change: {}".format(self.pal_data[pal]["Definition"]))
                defintion = input("definition: ")
                self.pal_data[pal]["Definition"] = defintion

            elif user_option == "3":
                print("last change: {}".format(", ".join(self.pal_data[pal]["Translation"])))
                print("Write the words separating by comas (,)")
                translation = input("Palabra: ")
                translation = [pal.strip() for pal in translation.split(',')]
                self.pal_data[pal]["Translation"] = translation

            elif user_option == "4":
                print("last change: {}".format(self.pal_data[pal]["Example"]))
                example = input("example: ")
                self.pal_data[pal]["Example"] = example
            
            jsonReader.dictToJson(PATH_DATA, self.pal_data)  
            my_print.message_press_any_btn()
Esempio n. 4
0
    def modify_word(self):
        print('Modify the attributes about some word\n')

        dict_list_pal = my_sort.date(self.pal_data)
        my_print.show_list_words(dict_list_pal)

        print('Please choice some word that do you want to modify')
        user_num = int(input('option: '))

        pal = dict_list_pal[user_num]
        pal_like_dict = self.pal_data[pal]

        self.show_word(pal_like_dict)

        while True:
            print("What attribute do you want change?\n"
                  "     1) Word\n"
                  "     2) Definition\n"
                  "     3) Traslation\n"
                  "     4) Example\n\n"
                  "     5) Back <--")

            user_option = input('option: ')
            print()
            
            if user_option == "5":
                return
            
            user_modify = input('write the change: ')            
            if user_option == "1":
                self.pal_data[pal]['Word'] = user_modify
                self.pal_user[pal]['Word'] = user_modify
            elif user_option == "2":
                self.pal_data[pal]['Definition'] = user_modify
                self.pal_user[pal]['Definition'] = user_modify
            elif user_option == "3":
                self.pal_data[pal]['Translation'] = user_modify
                self.pal_user[pal]['Translation'] = user_modify
            elif user_option == "4":
                self.pal_data[pal]['Example'] = user_modify
                self.pal_user[pal]['Example'] = user_modify
            
            self.save_status()     
            my_print.message_press_any_btn()
Esempio n. 5
0
    def add_word_to_user(self):
        dict_list_pal = my_sort.date(self.pal_data, self.pal_user)

        if dict_list_pal:
            print(
                "Please write the numbers separating by commas the words that do you want:\n"
                "(Example: 1,2,5,... or 3:15 -> 3,4,5,...,14,15)\n")

            my_print.show_list_words(dict_list_pal)

            user_petition = input('Option(s): ')
            user_petition.strip()
            print()

            # Lo numeros ingresados serán llevado a una lista de números
            if ':' in user_petition:
                pos = user_petition.index(':')
                num_first = int(user_petition[:pos])
                num_last = int(user_petition[pos + 1:]) + 1
                user_petition = [n for n in range(num_first, num_last)]

            else:
                user_petition = user_petition.split(',')
                user_petition = [int(n) for n in user_petition]

            for n in user_petition:
                pal = dict_list_pal[n]
                self.pal_user.append(pal)

            jsonReader.dictToJson(PATH_USER_LESSON, self.pal_user)

            my_print.message_press_any_btn(True)

        else:
            print(
                "There's no words in the DATA that be different that you have...\n"
            )
            print()
            my_print.message_press_any_btn()

        return
Esempio n. 6
0
    def customize_lesson(self):
        while True:
            print('We will customize our lesson, this are your words:\n')

            dict_list_pal = my_sort.date(self.pal_user)
            my_print.show_list_words(dict_list_pal)

            print("What do you want:\n"
                  "     1) Add\n"
                  "     2) Remove\n\n"
                  "     3) Back MENU<--\n")

            user_option = input('Option: ')
            print()

            if user_option == "1":
                self.add_word_to_user()
            elif user_option == "2":
                self.remove_word()
            elif user_option == "3":
                return
Esempio n. 7
0
    def remove_word(self, forever=False):

        # Volver si no hay palabras que retirar
        if (forever and not self.pal_data) or (not forever and not self.pal_user):
            input("There's no words... ")
            print()
            return

        print('Please write the numbers separating by commas the words that do you want remove:\n'
             '(Example: 1,2,5,...)\n')

        if forever:
            print('This option also will be in the words of your custom lesson...\n')
            dict_list_pal = my_sort.date(self.pal_data)
        else:
            dict_list_pal = my_sort.date(my_converter.List_toDict(self.pal_user, self.pal_data))

        my_print.show_list_words(dict_list_pal)
        user_petition = input('Option(s): ')

        if ':' in user_petition:
            pos = user_petition.index(':')
            num_first = int(user_petition[:pos])
            num_last = int(user_petition[pos+1:]) + 1
            user_petition = [n for n in range(num_first, num_last)]

        else:
            user_petition = user_petition.split(',')
            user_petition = [int(n) for n in user_petition]

        for n in user_petition:
            key_word = dict_list_pal[n]

            if forever:
                is_unique = False
                if not key_word[-2] == "_":
                    is_unique = True

                if is_unique:
                    try:
                        for name_file in self.pal_data[key_word]["Sound"]:
                            os.remove(name_file)
                    except KeyError:
                        pass
               
                # Eliminamos la palabra de DATA
                del self.pal_data[key_word]

                if not is_unique:
                    group = [w for w in list(self.pal_data.keys()) if key_word[:-1] in w]
                    group.sort()
                    k = len(group)
                    if k > 1:
                        for w, i in zip(group, range(1,k+1)):
                            self.pal_data[w[:-1]+str(i)] = self.pal_data.pop(w)
                            if w in self.pal_user:
                                self.pal_user.remove(w)
                                self.pal_user.append(w[:-1]+str(i))

                    else:
                        self.pal_data[group[0][:-2]] = self.pal_data.pop(group[0])
                        self.pal_user.remove(group[0])
                        self.pal_user.append(group[0][:-2])

            try:
                self.pal_user.remove(key_word)
            except ValueError:
                pass

        jsonReader.dictToJson(PATH_DATA, self.pal_data)
        jsonReader.dictToJson(PATH_USER_LESSON, self.pal_user)

        my_print.message_press_any_btn(True)
        return
Esempio n. 8
0
    def modify_word(self):
        print('Modify the attributes about some word\n')

        dict_list_pal = my_sort.date(self.pal_data)
        my_print.show_list_words(dict_list_pal)

        print('Please choice some word that do you want to modify')
        user_num = int(input('option: '))

        pal = dict_list_pal[user_num]
        pal_like_dict = self.pal_data[pal]

        self.show_word(pal_like_dict)

        while True:
            print("What attribute do you want change?\n"
                  "     1) Word\n"
                  "     2) Meanings\n"
                  "     3) Back <--")

            user_option = input('option: ')
            print()

            if user_option == "3":
                return

            if user_option == "1":
                print("last change: {}".format(self.pal_data[pal]["Word"]))
                user_modify = input("write the change: ")
                self.pal_data[pal]['Word'] = user_modify
                self.pal_user.remove(pal)
                self.pal_user.append(user_modify)
            elif user_option == "2":
                list_aux = list(enumerate(self.pal_data[pal]['Meanings']))
                for elem in list_aux:
                    num = elem[0] + 1
                    definition = elem[1]["definition"]
                    example = elem[1]["example"]
                    translation = elem[1]["translation"]
                    print("{})Definition: {}\n"
                          "  Example: {}\n"
                          "  Translation: {}\n".format(num, definition,
                                                       example,
                                                       ", ".join(translation)))
                print("0) Back <-")
                print("99) Add new mean")

                print()
                print("Choise the mean that you want modify")
                user_num = (input("Option: "))
                if user_num == "0":
                    return
                elif user_num == "99":
                    meanings = list()
                    while True:
                        definition = input("Definition: ")

                        print("Write the words separating by comas (,)")
                        translation = input("Palabra: ")
                        translation = [
                            pal.strip() for pal in translation.split(',')
                        ]

                        example = input("Example of use: ")

                        meanings.append({
                            "definition": definition,
                            "example": example,
                            "translation": translation,
                            "chosen": False
                        })

                        print("Do you wanna add more means?")
                        print("     1) Yes" "     2) No -> Press Enter")
                        user_ask = input("Option: ")
                        if user_ask == "1":
                            continue
                        else:
                            self.pal_data[pal]["Meanings"].extend(meanings)
                            break
                else:
                    while True:
                        user_num = int(user_num) - 1
                        if len(self.pal_data[pal]['Meanings']) - 1 < user_num:
                            print("Try again...")
                            user_num = (input("Option: "))
                        else:
                            break
                    print("What item do you want modify?")
                    print("   1) Definition\n"
                          "   2) Example\n"
                          "   3) Spanish\n"
                          "   4) Delete this mean")
                    user_option = input("Option: ")
                    if user_option == "1":
                        print("last change: {}".format(
                            self.pal_data[pal]['Meanings'][user_num]
                            ['definition']))
                        definition = input("new change: ")
                        self.pal_data[pal]['Meanings'][user_num][
                            'definition'] = definition
                    elif user_option == "2":
                        print("last change: {}".format(
                            self.pal_data[pal]['Meanings'][user_num]
                            ['example']))
                        example = input("new change: ")
                        self.pal_data[pal]['Meanings'][user_num][
                            'example'] = example
                    elif user_option == "3":
                        print("last change: {}".format(
                            ", ".join(self.pal_data[pal]['Meanings'][user_num]
                                      ['translation'])))
                        translation = input("new change: ")
                        self.pal_data[pal]['Meanings'][user_num][
                            'translation'] = [
                                p.strip() for p in translation.split(',')
                            ]
                    elif user_option == "4":
                        del self.pal_data[pal]['Meanings'][user_num]

            jsonReader.dictToJson(PATH_DATA, self.pal_data)

            my_print.message_press_any_btn()