def _get_media_from_models(self): anki_exporter = AnkiExporter(self.collection) model_ids = [ model.anki_dict["id"] for model in self.metadata.models.values() ] return anki_exporter.get_files_for_models(model_ids, self.collection.media.dir())
def JxExport2Anki(): JxPath = unicode(getSaveFile(mw, _("Choose file to export to"), "","Anki Deck (*.anki)", ".anki")) if not JxPath: return if not JxPath.lower().endswith(".anki"): JxPath += ".anki" if path.exists(JxPath): # check for existence after extension if not askUser("This file exists. Are you sure you want to overwrite it?"): return Ids=[] from database import eDeck for (myType,atom) in User: try: for factId in eDeck.atoms[myType][atom].keys(): Ids.extend(eDeck.states[factId][1].keys()) except: pass from anki.exporting import AnkiExporter JxExport = AnkiExporter(mw.deck) JxExport.limitCardIds = Ids JxExport.exportInto(JxPath) mw.help.showText("Successfully exported " + str(len(Ids)) + " cards")
def JxExport2Anki(): JxPath = unicode(getSaveFile(mw, _("Choose file to export to"), "","Anki Deck (*.anki)", ".anki")) if not JxPath: return if not JxPath.lower().endswith(".anki"): JxPath += ".anki" if path.exists(JxPath): # check for existence after extension if not ui.utils.askUser("This file exists. Are you sure you want to overwrite it?"): return import string # Query = u"""select cards.id from facts,cards,fields,fieldModels, models where # cards.factId = facts.id and facts.id = fields.factId and fields.fieldModelId = fieldModels.id and facts.modelId = models.id and # fieldModels.name = "Expression" and models.tags like "%%Japanese%%" and fields.value in (%s) group by cards.id""" % string.join([unicode("'" + Stuff + "',") for Stuff in User])[0:-1] # Ids = mw.deck.s.column0(Query) Ids=[] for (Stuff,Id) in User: Ids.append(Id) from anki.exporting import AnkiExporter JxExport = AnkiExporter(mw.deck) JxExport.limitCardIds = Ids JxExport.exportInto(JxPath)
def _copyToTmpDeck(self, name="cram.anki", tags="", ids=[]): # fixme: use namedtmp ndir = tempfile.mkdtemp(prefix="anki") path = os.path.join(ndir, name) from anki.exporting import AnkiExporter e = AnkiExporter(self.deck) e.includeMedia = False if tags: e.limitTags = parseTags(tags) if ids: e.limitCardIds = ids path = unicode(path, sys.getfilesystemencoding()) e.exportInto(path) return (e, path)
class NoteModelFileProvider(FileProvider): anki_collection: Any model_ids: Iterable[int] models: Iterable = field(init=False) anki_exporter: AnkiExporter = field(init=False) def __post_init__(self): self.anki_exporter = AnkiExporter(self.anki_collection) self.models = seq(self.model_ids) \ .map(self.anki_collection.models.get) \ .filter(lambda m: m is not None).to_list() def get_files(self) -> Set[str]: return seq(os.listdir(self.anki_collection.media.dir())) \ .filter(lambda fn: fn.startswith("_")) \ .filter(self.belongs_to_any_model) \ .to_set() def belongs_to_any_model(self, file_name: str) -> bool: return seq(self.models) \ .map(lambda model: self.anki_exporter._modelHasMedia(model, file_name)) \ .any()
def __post_init__(self): self.anki_exporter = AnkiExporter(self.anki_collection) self.models = seq(self.model_ids) \ .map(self.anki_collection.models.get) \ .filter(lambda m: m is not None).to_list()