py/gadict_srs_anki.py
changeset 1008 dc218f2b784d
parent 931 9a5f97027ee7
child 1215 d7394ed6693d
equal deleted inserted replaced
1007:672f0b73889a 1008:dc218f2b784d
   220         self.collection = collection = anki.Collection(os.path.join(self.tmpdir, 'collection.anki2'))
   220         self.collection = collection = anki.Collection(os.path.join(self.tmpdir, 'collection.anki2'))
   221 
   221 
   222         deck_id = collection.decks.id(self.name)
   222         deck_id = collection.decks.id(self.name)
   223 
   223 
   224         # It is essential to keep model['id'] unchanged between upgrades!!
   224         # It is essential to keep model['id'] unchanged between upgrades!!
   225         model_id = int(hashlib.sha1(self.name).hexdigest(), 16) % (2**63)
   225         model_id = int(hashlib.sha1(self.name.encode('utf-8')).hexdigest(), 16) % (2**63)
   226 
   226 
   227         ################################################################
   227         ################################################################
   228         # Regular card model. SafeBack doesn't include examples to not spoil
   228         # Regular card model. SafeBack doesn't include examples to not spoil
   229         # word spelling.
   229         # word spelling.
   230         model = collection.models.new(self.name + "_frontback")
   230         model = collection.models.new(self.name + "_frontback")
   338         """
   338         """
   339         :nodetype     used to generate different notes from same headword
   339         :nodetype     used to generate different notes from same headword
   340         :unambiguous  used if several subsequent article with same headword (and different pronunciation)
   340         :unambiguous  used if several subsequent article with same headword (and different pronunciation)
   341         """
   341         """
   342         if unambiguous > 0:
   342         if unambiguous > 0:
   343             h = hashlib.md5(":".join((self.name, nodetype, headword, str(unambiguous))))
   343             h = hashlib.md5(":".join((self.name, nodetype, headword, str(unambiguous))).encode('utf-8'))
   344         else:
   344         else:
   345             h = hashlib.md5(":".join((self.name, nodetype, headword)))
   345             h = hashlib.md5(":".join((self.name, nodetype, headword)).encode('utf-8'))
   346         return h.hexdigest()
   346         return h.hexdigest()
   347 
   347 
   348     def add_note(self, headword, unambiguous, front, back, safeback, freq="", tags=None):
   348     def add_note(self, headword, unambiguous, front, back, safeback, freq="", tags=None):
   349         note = anki.notes.Note(self.collection, self.model)
   349         note = anki.notes.Note(self.collection, self.model)
   350         note['Front'] = front
   350         note['Front'] = front