Пример #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
Пример #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
Пример #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()
Пример #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()
Пример #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
Пример #6
0
    def run(self):

        while True:

            if self.mode_repeat:
                list_pal = self.list_pal_mistaken
            else:
                list_pal_more = sample(list(self.pal_data.keys()), 3)
                for pal in list_pal_more:
                    self.pal_user[pal] = self.pal_data[pal]
                
                list_pal = list(self.pal_user.keys())


            print("We will start with our lesson.\n\n"
              "There are {} words today.\n".format(len(list_pal)))
            
            
            total_pal = len(list_pal)
            pal_hechas = 0
            self.list_pal_mistaken = list()

            while list_pal:

                self.se_equivoco_english = False
                self.se_equivoco_spanish = False

                # pal_chosen: 'pal': {information about pal}
                pal_chosen = self.pal_user[choice(list_pal)]
                pal_sound_chosen = choice(pal_chosen['Sound'])
                pyglet.resource.media(pal_sound_chosen).play()

                points = self.enter_word(pal_chosen, 'english')
                self.process_points(points)

                print('Now, write its translation')

                points = self.enter_word(pal_chosen, 'spanish')
                self.process_points(points)

                self.show_word(pal_chosen, pal_sound_chosen)

                if self.se_equivoco_english:
                    self.rewrite_word(pal_chosen, 'english')

                if self.se_equivoco_spanish:
                    self.rewrite_word(pal_chosen, 'spanish')

                if self.se_equivoco_english or self.se_equivoco_spanish:
                    self.list_pal_mistaken.append(pal_chosen['Word'])  

                list_pal.remove(pal_chosen['Word'])
                pal_hechas += 1

                self.show_progress(pal_hechas, total_pal)

                if list_pal:
                    my_print.message_press_any_btn()

            print('You finished the lesson :D')
            print()

            # Verificar si tuvo más del 80 porciento de score
            self.show_award(80, total_pal)

            # self.ver_premio()
            my_print.message_press_any_btn()

            self.repeat_words()

            if not self.mode_repeat:
                print("What do you want now:\n"
                      "1) Repeat all lesson again\n\n"
                      "2) Back MENU <--\n"
                      "3) EXIT\n")

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

                if user_option == "2":
                    break
                elif user_option == "3":
                    sys.exit()
Пример #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
Пример #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()
Пример #9
0
    def run(self):

        while True:

            if self.mode_repeat:
                list_pal = self.list_pal_mistaken
                total_pal = len(list_pal)
            else:
                if self.mode_test:
                    try:
                        list_pal = sample(list(self.pal_data.keys()), 20)
                    except ValueError:
                        list_pal = list(self.pal_data.keys())

                #elif self.mode_seccion:
                #    list_pal = list(self.list_pal_seccion)
                else:
                    list_pal = list(self.pal_user)
                    k = 0
                    for pal in list_pal:
                        k += len(self.pal_data[pal]["Meanings"])
                    total_pal = k

            self.list_pal_seccion = tuple(list_pal)

            print("We will start with our lesson.\n\n"
                  "There are {} words today.\n".format(total_pal))

            pal_hechas = 0
            self.list_pal_mistaken = list()

            while list_pal:

                self.se_equivoco_english = False
                self.se_equivoco_translation = False

                # pal_chosen: 'pal': {information about pal}
                pal_chosen = self.pal_data[choice(list_pal)]
                pal_sound_chosen = choice(pal_chosen['Sound'])
                pyglet.resource.media(pal_sound_chosen).play()

                points = self.enter_word(pal_chosen, 'english')
                self.process_points(points)

                points = self.enter_word(pal_chosen, 'spanish')
                self.process_points(points)

                self.show_word(pal_chosen, pal_sound_chosen)

                if self.se_equivoco_english:
                    self.rewrite_word(pal_chosen, 'english')

                if self.se_equivoco_translation:
                    self.rewrite_word(pal_chosen, 'spanish')

                if self.se_equivoco_english or self.se_equivoco_translation:
                    self.list_pal_mistaken.append(pal_chosen['Word'])

                for m in pal_chosen["Meanings"]:
                    if m["chosen"]:
                        m["shown"] = True

                all_shown = True
                for mean in pal_chosen['Meanings']:
                    if not mean['shown']:
                        all_shown = False

                if all_shown:
                    for mean in pal_chosen['Meanings']:
                        mean['shown'] = False
                    list_pal.remove(pal_chosen['Word'])

                pal_hechas += 1
                self.show_progress(pal_hechas, total_pal)

                if list_pal:
                    my_print.message_press_any_btn()

            print('You finished the lesson :D')
            print()

            # Verificar si tuvo más del 80 porciento de score
            self.show_award(80, total_pal)

            # self.ver_premio()
            my_print.message_press_any_btn()

            if self.list_pal_mistaken:
                self.repeat_words()

            if not self.mode_repeat or not self.list_pal_mistaken:
                print("What do you want now:\n"
                      #"1) Repeat this seccion\n"
                      "1) Repeat all lesson again\n\n"
                      "2) Back MENU <--\n"
                      "3) EXIT\n")

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

                #if user_option == "1":
                #    self.mode_seccion = True
                #    self.mode_repeat = False
                if user_option == "1":
                    self.mode_seccion = False
                    self.mode_repeat = False
                    list_pal = self.pal_user
                elif user_option == "2":
                    break
                elif user_option == "3":
                    sys.exit()