Beispiel #1
0
def modify():
    '''Modify an existing word.'''
    try:
        conword = input("Enter word in conlang: ")
        if Library.wordExists(conlang=conword):
            word = Library.findConWord(conword, pop=False)
            outputWord(word)
        else:
            print("Word does not exist")
            return

        keys = list(word.keys())
        keys.remove("id")
        keys.append("NEW")
        keys.append("DELETE")

        another = True

        while another:
            key = IOHelper.chooseOption("Enter field to modify", keys)

            if key == "NEW":
                word = addCustomFields(word, prompt=False)
            elif key == "DELETE":
                keys.remove("NEW")
                keys.remove("DELETE")
                keys.remove("english")
                keys.remove("word")
                key = IOHelper.chooseOption("Enter field to delete", keys)
                keys.remove(key)
                del word[key]

                keys.insert(0, "english")
                keys.insert(0, "word")
                keys.append("NEW")
                keys.append("DELETE")
            else:
                if key in ["word", "english"]:
                    word[key] = input("Enter new value: ")
                else:
                    values = Library.getFieldOptions(key)
                    values.append("other")

                    v = IOHelper.chooseOption("Enter word value",
                                              values)

                    if v == "other":
                        v = input("Enter new value: ")

                    word[key] = v

            another = not IOHelper.yesNo("Finished modifying")

        # Delete word if finished modifying and add new word
        Library.findConWord(conword, pop=True)
        Library.addWord(word)

    except KeyboardInterrupt:
        pass
Beispiel #2
0
def importWords():
    '''Add words from csv file to database.'''
    filename = input("Enter location of word csv file: ")
    try:
        with open(filename, "r") as f:
            reader = csv.DictReader(f)
            for word in reader:
                Library.addWord(word)
            print("Words successfully imported!")

    except FileNotFoundError:
        print("File not found! Double-check the path you are using.")
Beispiel #3
0
def add():
    '''Interface for addWord().'''
    word = {}
    word['english'] = input("Enter meaning in English: ")
    word['word'] = input("Enter word in conlang: ")

    forms = Library.getFieldOptions("form")
    forms.append("other")

    form = IOHelper.chooseOption("Enter word form",
                                forms)
    if form == "other":
        form = input("Enter new word form: ")

    word['form'] = form

    word = addCustomFields(word)
    Library.addWord(word)
    print("Word saved in database!")
Beispiel #4
0
def generate(english=None):
    '''Interface to generateWord().'''
    if english is None:
        english = input("Enter word in English: ")

    if Library.wordExists(english=english):
        print("Word already exists!")
        w = Library.findEnglishWord(english)
        outputWord(w)
        return 1

    forms = Library.getFieldOptions("form")
    forms.append("other")

    form = IOHelper.chooseOption("Enter word form",
                                 forms)

    if form == "other":
        form = input("Enter new word form: ")

    finalised = False
    while finalised is not True:
        word = Library.generateWord(english, form, wordgensettings)
        while Library.wordExists(conlang=word['word']):
            word = Library.generateWord(english, form, wordgensettings)
        #clearScreen()
        outputWord(word, "conlang")

        accepted = IOHelper.chooseOption("Accept word", ["y", "n", "e"])
        if accepted == "y":
            finalised = True
        elif accepted == "e":
            word['word'] = input("Enter modified word: ")
            finalised = True

    word = addCustomFields(word)

    Library.addWord(word)
    print("Word saved in database!")