Example #1
0
    def rename_dictionary():
        """
        Rename dictionary
        """
        dictionary = input(_('Choose the dictionary:  '))

        if db.check_dictionary_exist(dictionary):
            new = input(_('Choose new name for dictionary:  '))
            if not db.check_dictionary_exist(new):
                confirm = input(
                    _('Are you sure you want to rename the dictionary? y/n:'))
                if confirm in CONF_LIST:
                    result = db.rename_dictionary(dictionary, new)
                    if result:
                        print(
                            _("Dictionary '{old}' renamed "
                              "to '{new}'".format(old=dictionary, new=new)))
                    else:
                        print(
                            _('Rename was canceled, choose another dictionary name!'
                              ))
                else:
                    print(_('Rename canceled'))
            else:
                print(
                    _('This dictionary is already in DB, use another dictionary name'
                      ))
                Dictionaries.list_dictionaries()
        else:
            print(_('This dictionary doesn\'t exists'))
            Dictionaries.list_dictionaries()
Example #2
0
 def dell_dictionary():
     """
     Delete dictionary
     """
     dictionary = input(_('choose the dictionary: '))
     dictionary_id = db.check_dictionary_exist(dictionary)
     if dictionary_id:
         confirm = input(
             _('Are you sure you want to delete the dictionary? y/n: '))
         if confirm in CONF_LIST:
             result = db.del_dictionary(dictionary_id)
             if result:
                 print(
                     _("Dictionary '{dictionary}' was deleted".format(
                         dictionary=dictionary)))
             else:
                 print(
                     _("Dictionary '{dictionary}' wasn't "
                       "deleted".format(dictionary=dictionary)))
         else:
             print(_('Delete canceled'))
     else:
         print(
             _("Dictionary '{dictionary}' doesn't exist".format(
                 dictionary=dictionary)))
Example #3
0
    def del_word_from_dic(word='', dictionary=''):
        """
        Delete word from dictionary
        """
        if word == '':
            word = input(
                _('Type the word that you want to delete from dictionary: '))
        if dictionary == '':
            dictionary = input(_('Choose the dictionary: '))

        if db.check_word_exist(word) and db.check_dictionary_exist(dictionary):
            result = db.dell_word_from_dictionary(
                db.check_dictionary_exist(dictionary),
                db.check_word_exist(word))
            if result:
                print(
                    _("Word '{word}' was successfully deleted from dictionary"
                      " '{dictionary}'!".format(word=word,
                                                dictionary=dictionary)))
            else:
                print("Error! The word wasn't deleted")

        elif not db.check_word_exist(word) and not db.check_dictionary_exist(
                dictionary):
            print(
                _("Dictionary '{dictionary}' does not exist".format(
                    dictionary=dictionary)))
            print(_("Word '{word}' not exist".format(word=word)))
        elif not db.check_dictionary_exist(dictionary):
            print(
                _("Dictionary '{dictionary}' does not exist".format(
                    dictionary=dictionary)))
        elif not db.check_word_exist(word):
            print(
                _("Word '{word}' was not in the dictionary "
                  "'{dictionary}'".format(word=word, dictionary=dictionary)))
Example #4
0
 def create_dictionary():
     """
     Create new dictionary
     """
     dictionary = input(_('Choose the name for the dictionary: '))
     if not db.check_dictionary_exist(dictionary):
         comment = input(_('Comments: '))
         result = db.create_dictionary(dictionary, comment)
         if result:
             print("Dictionary \'{name}\' has been created!".format(
                 name=dictionary))
         else:
             print("Dictionary \'{name}\' wasn't created!".format(
                 name=dictionary))
     else:
         print(
             'Dictionary \'{name}\' already exists! Please, choose another name '
             'for dictionary.'.format(name=dictionary))
Example #5
0
def add_word_to_dictionary(word):
    """
    Function adds words to the dictionary
    this function is used in class Words, methods:
     * analyze_book_words
     * add_word_2dic
    """
    separator4()
    print(_('List of dictionaries: '))
    for name in db.list_dictionary():
        print('     ', name[0])
    dictionary = input(_('Choose the dictionary: '))
    if db.check_dictionary_exist(dictionary):
        db.addword_2_dictionary(dictionary, word[0])
        print(
            _("The word '{word}' was successfully added to the dictionary!".
              format(word=word[0])))
        separator4()
    else:
        print(_("Dictionary doesn't exist. Please check spelling!"))
Example #6
0
    def list_word_from_dic():
        """
        Print the list of words in dictionary
        """
        dictionary = ''
        while dictionary == '':
            # Default Dictionary wasn't chosen
            if Words.dictionary == '':
                dictionary = input(_('Type the name of the dictionary: '))
                if db.check_dictionary_exist(dictionary):
                    Words.dictionary = dictionary
                else:
                    print(
                        _("Dictionary '{dictionary}' doesn't exist. Please, choose the "
                          "dictionary".format(dictionary=dictionary)))
                    print(_('List of dictionaries:'))
                    for name in db.list_dictionary():
                        print('     ', name[0])
                    separator4()
                    dictionary = ''
            # Default Dictionary exist
            else:
                print(
                    _("'{default_dictionary}' - dictionary "
                      "by default".format(
                          default_dictionary=Words.dictionary)))
                dictionary = input(
                    _('Inter new name of the dictionary/or leave the field empty: '
                      ))
                if dictionary == '':
                    dictionary = Words.dictionary
                else:
                    if db.check_dictionary_exist(dictionary):
                        Words.dictionary = dictionary
                    else:
                        print(
                            _("Dictionary '{dictionary}' doesn't exist. "
                              "Please, choose the "
                              "dictionary".format(dictionary=dictionary)))
                        print(_('List of dictionaries:'))
                        for name in db.list_dictionary():
                            print('     ', name[0])
                        separator4()
                        dictionary = ''

        # Checking the dictionary
        listword = db.select_from_dictionary(dictionary, Words.list_order,
                                             Words.order_rul)
        if listword:
            separator4()
            print(
                _("Dictionary contains {amount} words".format(
                    amount=len(listword))))
            Words.select_number_of_words()
            Words.select_words_order()
            listword = db.select_from_dictionary(dictionary, Words.list_order,
                                                 Words.order_rul)
            separator4()
            print_words(listword, length=Words.list_length)
        else:
            print("Dictionary is empty")