def save_to_collection(self, collection, deck, model_map_cache): # Todo uuid match on existing notes note_model = deck.metadata.models[self.note_model_uuid] # You may ask WTF? Well, it seems anki has 2 ways to identify deck where to place card: # 1) Looking for existing cards of this note # 2) Looking at model->did and to add new cards to correct deck we need to modify the did each time # ;( note_model.anki_dict["did"] = deck.anki_dict["id"] self.anki_object = AnkiNote.get_by_uuid(collection, self.get_uuid()) new_note = self.anki_object is None if new_note: self.anki_object = AnkiNote(collection, note_model.anki_dict) else: self.handle_model_update(collection, model_map_cache) self.anki_object.__dict__.update(self.anki_object_dict) self.anki_object.mid = note_model.anki_dict["id"] self.anki_object.mod = anki.utils.intTime() self.anki_object.flush() if new_note: collection.addNote(self.anki_object) else: self.move_cards_to_deck(deck.anki_dict["id"])
def get_note(self, uuid: str): query = "select id from notes where guid=?" note_id = self.collection.db.scalar(query, uuid) if not note_id: return None return AnkiNote(self.collection, id=note_id)
def get_anki_note_from_evernote_guid(self, evernote_guid): col = self.collection() ids = col.findNotes(FIELDS.EVERNOTE_GUID_PREFIX + evernote_guid) if not ids or not ids[0]: return None note = AnkiNote(col, None, ids[0]) return note
def save_to_collection(self, collection, deck, model_map_cache, import_config): # Todo uuid match on existing notes note_model = deck.metadata.models[self.note_model_uuid] self.anki_object = UuidFetcher(collection).get_note(self.get_uuid()) new_note = self.anki_object is None if new_note: self.anki_object = AnkiNote(collection, note_model.anki_dict) else: self.handle_model_update(collection, model_map_cache) self.handle_import_config_changes(import_config, note_model) self.anki_object.__dict__.update(self.anki_object_dict) self.anki_object.mid = note_model.anki_dict["id"] self.anki_object.mod = anki.utils.intTime() if new_note: collection.add_note(self.anki_object, deck.anki_dict["id"]) else: self.anki_object.flush() if not import_config.ignore_deck_movement: self.move_cards_to_deck(deck.anki_dict["id"])
def from_collection(cls, collection, note_id, note_models): anki_note = AnkiNote(collection, id=note_id) note = Note(anki_note) note_model = NoteModel.from_collection(collection, note.anki_object.mid) note_models.setdefault(note_model.get_uuid(), note_model) note.note_model_uuid = note_model.get_uuid() return note