def addTexts(self, source, texts, lesson=None, update=True): id = DB.getSource(source, lesson) r = [] for x in texts: h = hashlib.sha1() h.update(x.encode('utf-8')) txt_id = h.hexdigest() dis = 1 if lesson == 2 else None try: DB.execute("insert into text (id,text,source,disabled) values (?,?,?,?)", (txt_id, x, id, dis)) r.append(txt_id) except Exception, e: pass # silently skip ...
def addTexts(self, source, texts, lesson=None, update=True): id = DB.getSource(source, lesson) r = [] for x in texts: h = hashlib.sha1() h.update(x.encode('utf-8')) txt_id = h.hexdigest() dis = 1 if lesson == 2 else None try: DB.execute( "insert into text (id,text,source,disabled) values (?,?,?,?)", (txt_id, x, id, dis)) r.append(txt_id) except Exception, e: pass # silently skip ...
def addTexts(self, source, texts, lesson=None, update=True): id = DB.getSource(source, lesson) r = [] for x in texts: x = re.sub(Settings.get('sentence_strip'), ' ', x) h = hashlib.sha1() h.update(x.encode('utf-8')) txt_id = h.hexdigest() dis = 1 if lesson == 2 else None try: DB.execute("insert into text (id, text, source, disabled) values (?, ?, ?, ?)", (txt_id, x, id, dis)) except Exception: pass # silently skip ... r.append(txt_id) if update: self.update() if lesson: DB.commit() return r
def addTexts(self, source, texts, lesson=None, update=True): source = source +' Length:' + str(Settings.get('min_chars')) id = DB.getSource(source, lesson) r = [] for x in texts: x = self.cleanText(x) h = hashlib.sha1() h.update(x.encode('utf-8')) txt_id = h.hexdigest() dis = 1 if lesson == 2 else None try: DB.execute("insert into text (id, text, source, disabled) values (?, ?, ?, ?)", (txt_id, x, id, dis)) except Exception: pass # silently skip ... r.append(txt_id) if update: self.update() if lesson: DB.commit() return r