def addBasicCard(self, front: str, back: str, tags: List[str] = []): basicCard = self.generateCardOutline(model='Basic', tags=tags) basicCard['fields'] = { 'Front': front, 'Back': back } ankiApi.invoke('addNote', note=basicCard)
def generateCardOutline(self, model: str, tags: List[str] = []): if model not in ankiApi.invoke('modelNames'): raise Exception('card type does not yet exist') return { 'deckName': self.title, 'modelName': model, 'options': { 'allowDuplicate': False, 'duplicateScope': 'deck' }, 'fields': {}, 'tags': tags, }
def addCustomCard(self, model: str, fields: Dict[str, str], tags: List[str] = []): customCard = self.generateCardOutline(model=model, tags=tags) for fieldName, fieldContent in fields.items(): customCard['fields'][fieldName] = fieldContent ankiApi.invoke('addNote', note=customCard)
def create(self): ankiApi.invoke('createDeck', deck=self.title)
def __init__(self, title: str): self.title = title # If deck doesn't exist, make it if self.title not in ankiApi.invoke('deckNames'): self.create()