Beispiel #1
0
    def initialiseDB():
        try:
            loc = ("Mywords.xlsx")
            wb = xlrd.open_workbook(loc)
            sheet = wb.sheet_by_index(0)
            meanings = []
            # As we are generating options using meanings of other words, we
            # first get all the meanings and store them
            for i in range(sheet.nrows):
                meanings.append(sheet.cell_value(i, 1))

            # We insert the words one by one into the database
            for i in range(1, sheet.nrows):
                word = sheet.cell_value(i, 0).lower()
                meaning = sheet.cell_value(i, 1).lower()
                hint = sheet.cell_value(i, 2).lower()
                completed = sheet.cell_value(i, 3)
                options = []
                while len(options) <= 3:
                    newChoice = random.choice(meanings)
                    if newChoice not in options:
                        options.append(newChoice)
                newWord = Word(word=word,
                               meaning=meaning,
                               hint=hint,
                               options=options,
                               completed=completed)
                newWord.insert()
            return jsonify({"success": True})
        except BaseException:
            rollback()
            print("Word formatting error")
            abort(400)
Beispiel #2
0
    def add_word(self, widget):
        # show dialog and get button clicked code
        dialog = Dialog(self)
        response = dialog.run()
        dialog.destroy()

        if response != Gtk.ResponseType.OK:
            return

        # get entered word & translation
        word = dialog.word.strip()
        translation = dialog.translation.strip()
        if word == '' or translation == '':
            return

        # insert new word entered in database
        record = Word(word=word, translation=translation, date=datetime.now())
        pk = Word.insert(record)
        record = Word.retrieve_by_id(pk)

        # add inserted word to list view
        store = self.list.get_model()
        store.append([
            record.id, record.word, record.translation,
            record.date.strftime("%Y-%m-%d %H:%M:%S")
        ])
Beispiel #3
0
def process_line(line, is_positive):
    line = line.replace("\r", "").replace("\n", "").lower()
    spl = line.split(' ')
    if len(spl) > 1:
        for _i in range(0, len(spl)):
            c = 0
            while spl[_i] != morpher.parse(spl[_i])[0].normal_form:
                spl[_i] = morpher.parse(spl[_i])[0].normal_form
                c += 1
                if c > 5:
                    break
        line = ' '.join(spl)
    else:
        c = 0
        while line != morpher.parse(line)[0].normal_form:
            line = morpher.parse(line)[0].normal_form
            c += 1
            if c > 5:
                break
    Word.insert(word=line,
                is_positive=is_positive).on_conflict_ignore().execute()