def add_to_bd_type_two(filename, lines_count, start_id): try: row = start_id dao = Dao(True) file = open(filename, 'r', encoding="UTF-8") for i in range(0, lines_count, 3): keys = file.readline() answer = file.readline() nothing = file.readline() lst = tokenizer.tokenize_ru(keys) keywords = [] for word in lst: checked = spellchecker.correct(word) # stemmed = stemmer.stem(word) lemma = pymorphy2.MorphAnalyzer().parse(checked)[0].normal_form keywords.append(lemma) for keyword in keywords: sql = "insert into hack.`key`(text, answer_id) values ('" + keyword + "', " + str( row) + ");" dao.execute(sql) sql = "insert into answer(id, text) values (" + str( row) + ", '" + answer + "')" dao.execute(sql) row += 1 finally: file.close()
from db.dao import Dao dao = Dao() print(dao.execute("select * from hack.`answer`;"))