Toolkit to script flashcard generation for the spaced repetition learning app Anki. Model your Notes as Python classes. You can add methods to fetch data and format the fields. An example usage would be to scrape a dictionary for english words, their translation and maybe also a recording of the pronunciation. We could go further and do an image search and add this as context to the card.
- Anki running
- AnkiConnect extension installed
Source this in .zshrc or run it once and store it to speed up the evaluation.
Replace zsh for bash.
eval "$(_ANKER_COMPLETE=zsh_source anker)"They are a blueprint how to generate flashcards. They take inputs from a fetcher and specify how to transform the input possibly via creators and how to map them to fields.
Cards have to inherit from MetaCard from anker.meta and must implement
a prepare method that prepares the input. This method will be called for every input.
Inheritance may be used to have a generic language card that abstracts certain things like translating for multiple languages.
class Card(MetaCard):
deck_name = "Default"
model_name = "English"
tags = ["english::idioms"]
_field_Family = "Idioms"
def prepare(self, inputs, **kwds):
self.idiom, self.meaning, self.example = inputs
@field
def English(self):
return self.idiom
@field
def EE(self):
return self.meaning- deck_name
- The Anki deck the cards will be put in
- model_name
- The Anki model the cars will use.
- tags
- What Anki tags to add to the note.
- _field_XXX
- Static values for the field named XXX
- @field
- Decorate a method. The return value will be used for the field with the same name as the method.
- prepare()
- Prepares the input for use.
- hook()
- Some creators need to be updated each round.
Fetcher generate inputs for the card templates. Examples
- Scrape English idioms from a website
- Generate all multiplication calculations from with arguments from 1..100
Put your modules in anker.fetcher.
You need to expose a Fetcher object that is iterable.
Fetcher = (x for x in range(100))class Fetcher:
def __iter__(self):
for page in self.iter_pages():
yield from self.consume_soup(page)
# EllipsisImplementing __getitem__ and __len__ also works.
Creators take an input and create some content for it. Examples
- Translate a word with Google translate
- Find the URL to an image that is symbolic for a word.
- Find context for a word out of a book
Formatters provide utility decorators to beautify the outputs.