def addItemToCards(self,item): "This method actually do conversion" # new anki card card = ForeignCard() # clean Q and A card.fields.append(self._fudgeText(self._decode_htmlescapes(item.Question))) card.fields.append(self._fudgeText(self._decode_htmlescapes(item.Answer))) card.tags = u"" # pre-process scheduling data tLastrep = time.mktime(time.strptime(item.LastRepetition, '%d.%m.%Y')) tToday = time.time() # convert learning data if not self.META.resetLearningData: # migration of LearningData algorithm card.interval = item.Interval card.successive = item.Repetitions ##card.due = tToday + (float(item.Interval) * 86400.0) - tLastrep card.due = tLastrep + (float(item.Interval) * 86400.0) card.lastDue = 0 card.factor = float(item.AFactor.replace(',','.')) card.lastFactor = float(item.AFactor.replace(',','.')) # SM is not exporting all the information Anki keeps track off, so it # needs to be fudged card.youngEase0 = item.Lapses card.youngEase3 = item.Repetitions + item.Lapses card.yesCount = item.Repetitions card.noCount = item.Lapses card.reps = card.yesCount + card.noCount card.spaceUntil = card.due card.combinedDue = card.due # categories & tags # it's worth to have every theme (tree structure of sm collection) stored in tags, but sometimes not # you can deceide if you are going to tag all toppics or just that containing some pattern tTaggTitle = False for pattern in self.META.pathsToBeTagged: if item.lTitle != None and pattern.lower() in u" ".join(item.lTitle).lower(): tTaggTitle = True break if tTaggTitle or self.META.tagAllTopics: # normalize - remove diacritic punctuation from unicode chars to ascii item.lTitle = [ self._unicode2ascii(topic) for topic in item.lTitle] # Transfrom xyz / aaa / bbb / ccc on Title path to Tag xyzAaaBbbCcc # clean things like [999] or [111-2222] from title path, example: xyz / [1000-1200] zyx / xyz # clean whitespaces # set Capital letters for first char of the word tmp = list(set([ re.sub('(\[[0-9]+\])' , ' ' , i ).replace('_',' ') for i in item.lTitle ])) tmp = list(set([ re.sub('(\W)',' ', i ) for i in tmp ])) tmp = list(set([ re.sub( '^[0-9 ]+$','',i) for i in tmp ])) tmp = list(set([ capwords(i).replace(' ','') for i in tmp ])) tags = [ j[0].lower() + j[1:] for j in tmp if j.strip() <> ''] card.tags += u" ".join(tags) if self.META.tagMemorizedItems and item.Interval >0: card.tags += " Memorized" self.logger(u'Element tags\t- ' + card.tags, level=3) self.cards.append(card)