Documentation
¶
Overview ¶
Package anki provides functionality to create, read, and modify Anki decks and collections programmatically.
Index ¶
- func DefaultDeckCommon() *pb.DeckCommon
- func DefaultDeckConfig() *pb.DeckConfig
- func NewNotetypeConfig(css string, cloze bool) *pb.NotetypeConfig
- func NormalDeckKind(configID int64) *pb.DeckKind
- func Pack(w *zip.Writer, dir string) error
- func Unpack(r *zip.Reader, dir string) error
- type Card
- type CardQueue
- type CardType
- type Collection
- func (c *Collection) AddDeck(deck *Deck) error
- func (c *Collection) AddDeckConfig(config *DeckConfig) error
- func (c *Collection) AddMedia(name, path string) error
- func (c *Collection) AddNote(deckID int64, note *Note) error
- func (c *Collection) AddNotetype(notetype *Notetype) error
- func (c *Collection) Close() error
- func (c *Collection) CopyMedia(media Media) error
- func (c *Collection) CreateMedia(name string) (io.WriteCloser, error)
- func (c *Collection) DeleteConfig(key string) error
- func (c *Collection) DeleteDeckConfig(id int64) error
- func (c *Collection) DeleteMedia(name string) error
- func (c *Collection) DeleteNote(id int64) error
- func (c *Collection) DeleteNotetype(id int64) error
- func (c *Collection) DeleteTag(name string) error
- func (c *Collection) DumpTo(dir string) error
- func (c *Collection) GetCard(id int64) (*Card, error)
- func (c *Collection) GetConfig(key string) (*Config, error)
- func (c *Collection) GetDeck(id int64) (*Deck, error)
- func (c *Collection) GetDeckConfig(id int64) (*DeckConfig, error)
- func (c *Collection) GetMedia(name string) (Media, error)
- func (c *Collection) GetNote(id int64) (*Note, error)
- func (c *Collection) GetNotetype(id int64) (*Notetype, error)
- func (c *Collection) GetTag(name string) (*Tag, error)
- func (c *Collection) LastSyncTime() time.Time
- func (c *Collection) ListCards(opts *ListCardsOptions) iter.Seq2[*Card, error]
- func (c *Collection) ListConfigs(*ListConfigsOptions) iter.Seq2[*Config, error]
- func (c *Collection) ListDeckConfigs(*ListDeckConfigsOptions) iter.Seq2[*DeckConfig, error]
- func (c *Collection) ListDecks(opts *ListDecksOptions) iter.Seq2[*Deck, error]
- func (c *Collection) ListMedia(opts *ListMediaOptions) iter.Seq2[Media, error]
- func (c *Collection) ListNotes(opts *ListNotesOptions) iter.Seq2[*Note, error]
- func (c *Collection) ListNotetypes(opts *ListNotetypesOptions) iter.Seq2[*Notetype, error]
- func (c *Collection) ListTags(*ListTagsOptions) iter.Seq2[*Tag, error]
- func (c *Collection) ModTime() time.Time
- func (c *Collection) OpenMedia(name string) (io.ReadCloser, error)
- func (c *Collection) SaveAs(path string) error
- func (c *Collection) SchemdModTime() time.Time
- func (c *Collection) SetConfig(config *Config) error
- func (c *Collection) SetDeck(cards []int64, deckID int64) error
- func (c *Collection) SetTag(tag *Tag) error
- func (c *Collection) USN() int64
- func (c *Collection) UpdateNote(note *Note) error
- func (c *Collection) UpdateNotetype(notetype *Notetype) error
- func (c *Collection) WriteMedia(name string, content []byte) error
- func (c *Collection) WriteTo(w io.Writer) (int64, error)
- type Config
- type Deck
- type DeckConfig
- type DeckName
- type Field
- type ListCardsOptions
- type ListConfigsOptions
- type ListDeckConfigsOptions
- type ListDecksOptions
- type ListMediaOptions
- type ListNotesOptions
- type ListNotetypesOptions
- type ListTagsOptions
- type Media
- type Note
- type Notetype
- type Tag
- type Template
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultDeckCommon ¶
func DefaultDeckCommon() *pb.DeckCommon
DefaultDeckCommon returns the default deck common settings.
func DefaultDeckConfig ¶
func DefaultDeckConfig() *pb.DeckConfig
DefaultDeckConfig returns the default deck configuration.
func NewNotetypeConfig ¶
func NewNotetypeConfig(css string, cloze bool) *pb.NotetypeConfig
NewNotetypeConfig creates a new notetype configuration. If cloze is true, the notetype is configured for cloze deletion.
func NormalDeckKind ¶
NormalDeckKind creates a normal deck kind with the given configuration ID.
Types ¶
type Card ¶
type Card struct {
ID int64
NoteID int64
DeckID int64
Ordinal int
Modified time.Time
USN int64
Type CardType
Queue CardQueue
Due int64
Interval int64
Factor int64
Repetitions int64
Lapses int64
Left int64
OriginalDue int64
OriginalDeckID int64
Flags int64
Data string
}
Card represents a card in Anki.
type CardQueue ¶
type CardQueue int
CardQueue represents the queue of a card.
const ( // CardQueueNew is the new card queue. CardQueueNew CardQueue = 0 // CardQueueLearn is the learning queue. CardQueueLearn CardQueue = 1 // CardQueueReview is the review queue. CardQueueReview CardQueue = 2 // CardQueueDayLearn is the day learning queue. CardQueueDayLearn CardQueue = 3 // CardQueuePreviewRepeat is the preview repeat queue. CardQueuePreviewRepeat CardQueue = 4 // CardQueueSuspended is the suspended queue. CardQueueSuspended CardQueue = -1 // CardQueueSchedBuried is the scheduler buried queue. CardQueueSchedBuried CardQueue = -2 // CardQueueUserBuried is the user buried queue. CardQueueUserBuried CardQueue = -3 )
type Collection ¶
type Collection struct {
// contains filtered or unexported fields
}
Collection represents an Anki collection.
func LoadDir ¶
func LoadDir(dir string) (*Collection, error)
LoadDir loads a collection from a directory
func ReadFrom ¶
func ReadFrom(r io.ReaderAt, size int64) (*Collection, error)
ReadFrom reads a collection from an io.ReaderAt.
func (*Collection) AddDeck ¶
func (c *Collection) AddDeck(deck *Deck) error
AddDeck adds a new deck to the collection. If the parent decks do not exist, they will be created automatically.
func (*Collection) AddDeckConfig ¶
func (c *Collection) AddDeckConfig(config *DeckConfig) error
AddDeckConfig adds a new deck configuration to the collection.
func (*Collection) AddMedia ¶
func (c *Collection) AddMedia(name, path string) error
AddMedia adds a media file from a path.
func (*Collection) AddNote ¶
func (c *Collection) AddNote(deckID int64, note *Note) error
AddNote adds a new note to the collection.
func (*Collection) AddNotetype ¶
func (c *Collection) AddNotetype(notetype *Notetype) error
AddNotetype adds a new notetype to the collection.
func (*Collection) Close ¶
func (c *Collection) Close() error
Close closes the collection and cleans up temporary files.
func (*Collection) CopyMedia ¶
func (c *Collection) CopyMedia(media Media) error
CopyMedia copies a media file to the collection.
func (*Collection) CreateMedia ¶
func (c *Collection) CreateMedia(name string) (io.WriteCloser, error)
CreateMedia creates a new media file and returns a writer.
func (*Collection) DeleteConfig ¶
func (c *Collection) DeleteConfig(key string) error
DeleteConfig deletes a configuration entry by key.
func (*Collection) DeleteDeckConfig ¶
func (c *Collection) DeleteDeckConfig(id int64) error
DeleteDeckConfig deletes a deck configuration by its ID.
func (*Collection) DeleteMedia ¶
func (c *Collection) DeleteMedia(name string) error
DeleteMedia deletes a media file.
func (*Collection) DeleteNote ¶
func (c *Collection) DeleteNote(id int64) error
DeleteNote deletes a note from the collection by its ID.
func (*Collection) DeleteNotetype ¶
func (c *Collection) DeleteNotetype(id int64) error
DeleteNotetype deletes a notetype by its ID.
func (*Collection) DeleteTag ¶
func (c *Collection) DeleteTag(name string) error
DeleteTag deletes a tag by name.
func (*Collection) DumpTo ¶
func (c *Collection) DumpTo(dir string) error
DumpTo dumps the collection to a directory.
func (*Collection) GetCard ¶
func (c *Collection) GetCard(id int64) (*Card, error)
GetCard gets a card by its ID.
func (*Collection) GetConfig ¶
func (c *Collection) GetConfig(key string) (*Config, error)
GetConfig gets a configuration entry by key.
func (*Collection) GetDeck ¶
func (c *Collection) GetDeck(id int64) (*Deck, error)
GetDeck gets a deck by its ID.
func (*Collection) GetDeckConfig ¶
func (c *Collection) GetDeckConfig(id int64) (*DeckConfig, error)
GetDeckConfig gets a deck configuration by its ID.
func (*Collection) GetMedia ¶
func (c *Collection) GetMedia(name string) (Media, error)
GetMedia gets a media file by name.
func (*Collection) GetNote ¶
func (c *Collection) GetNote(id int64) (*Note, error)
GetNote gets a note by its ID.
func (*Collection) GetNotetype ¶
func (c *Collection) GetNotetype(id int64) (*Notetype, error)
GetNotetype gets a notetype by its ID.
func (*Collection) GetTag ¶
func (c *Collection) GetTag(name string) (*Tag, error)
GetTag gets a tag by name.
func (*Collection) LastSyncTime ¶
func (c *Collection) LastSyncTime() time.Time
LastSyncTime returns the last sync time of the collection.
func (*Collection) ListCards ¶
func (c *Collection) ListCards(opts *ListCardsOptions) iter.Seq2[*Card, error]
ListCards lists cards with optional filtering.
func (*Collection) ListConfigs ¶
func (c *Collection) ListConfigs(*ListConfigsOptions) iter.Seq2[*Config, error]
ListConfigs lists all configuration entries.
func (*Collection) ListDeckConfigs ¶
func (c *Collection) ListDeckConfigs(*ListDeckConfigsOptions) iter.Seq2[*DeckConfig, error]
ListDeckConfigs lists all deck configurations.
func (*Collection) ListDecks ¶
func (c *Collection) ListDecks(opts *ListDecksOptions) iter.Seq2[*Deck, error]
ListDecks lists all decks.
func (*Collection) ListMedia ¶
func (c *Collection) ListMedia(opts *ListMediaOptions) iter.Seq2[Media, error]
ListMedia lists all media files.
func (*Collection) ListNotes ¶
func (c *Collection) ListNotes(opts *ListNotesOptions) iter.Seq2[*Note, error]
ListNotes lists notes with optional filtering.
func (*Collection) ListNotetypes ¶
func (c *Collection) ListNotetypes(opts *ListNotetypesOptions) iter.Seq2[*Notetype, error]
ListNotetypes lists all notetypes.
func (*Collection) ListTags ¶
func (c *Collection) ListTags(*ListTagsOptions) iter.Seq2[*Tag, error]
ListTags lists all tags.
func (*Collection) ModTime ¶
func (c *Collection) ModTime() time.Time
ModTime returns the modification time of the collection.
func (*Collection) OpenMedia ¶
func (c *Collection) OpenMedia(name string) (io.ReadCloser, error)
OpenMedia opens a media file for reading.
func (*Collection) SaveAs ¶
func (c *Collection) SaveAs(path string) error
SaveAs saves the collection to a file.
func (*Collection) SchemdModTime ¶
func (c *Collection) SchemdModTime() time.Time
SchemdModTime returns the schema modification time of the collection.
func (*Collection) SetConfig ¶
func (c *Collection) SetConfig(config *Config) error
SetConfig sets a configuration entry.
func (*Collection) SetDeck ¶
func (c *Collection) SetDeck(cards []int64, deckID int64) error
SetDeck moves a list of cards to a different deck.
func (*Collection) SetTag ¶
func (c *Collection) SetTag(tag *Tag) error
SetTag adds or updates a tag.
func (*Collection) UpdateNote ¶
func (c *Collection) UpdateNote(note *Note) error
UpdateNote updates an existing note in the collection.
func (*Collection) UpdateNotetype ¶
func (c *Collection) UpdateNotetype(notetype *Notetype) error
UpdateNotetype updates an existing notetype in the collection.
func (*Collection) WriteMedia ¶
func (c *Collection) WriteMedia(name string, content []byte) error
WriteMedia writes content to a media file.
type Deck ¶
type Deck struct {
ID int64
Name DeckName
Modified time.Time
USN int64
Common *pb.DeckCommon
Kind *pb.DeckKind
}
Deck represents a deck in Anki.
type DeckConfig ¶
DeckConfig represents a deck configuration in Anki.
type DeckName ¶
type DeckName string
DeckName is the name of a deck.
func JoinDeckName ¶
JoinDeckName joins deck name components into a single DeckName. In Anki, deck names are hierarchical, separated by "::". Internally, they are stored with the U+001F INFORMATION SEPARATOR ONE character.
func (DeckName) Components ¶
Components returns the individual components of the deck name.
func (DeckName) HumanString ¶
HumanString returns the deck name in a human-readable format, with "::" as the separator.
type Field ¶
type Field struct {
Ordinal int
Name string
Config *pb.FieldConfig
}
Field represents a field in a notetype.
type ListCardsOptions ¶
ListCardsOptions specifies options for listing cards.
type ListConfigsOptions ¶
type ListConfigsOptions struct{}
ListConfigsOptions specifies options for listing configuration entries.
type ListDeckConfigsOptions ¶
type ListDeckConfigsOptions struct{}
ListDeckConfigsOptions specifies options for listing deck configurations.
type ListDecksOptions ¶
type ListDecksOptions struct {
ParentName *DeckName
}
ListDecksOptions specifies options for listing decks.
type ListMediaOptions ¶
type ListMediaOptions struct {
// A glob pattern to filter media files by name.
Pattern *string
}
ListMediaOptions specifies options for listing media files.
type ListNotesOptions ¶
type ListNotesOptions struct {
NotetypeID *int64
}
ListNotesOptions specifies options for listing notes.
type ListNotetypesOptions ¶
type ListNotetypesOptions struct {
Name *string
}
ListNotetypesOptions specifies options for listing notetypes.
type ListTagsOptions ¶
type ListTagsOptions struct{}
ListTagsOptions specifies options for listing tags.
type Media ¶
type Media interface {
Name() string
Open() (io.ReadCloser, error)
}
Media is an interface for a media file.
type Note ¶
type Note struct {
ID int64
GUID string
NotetypeID int64
Modified time.Time
USN int64
Tags []string
Fields []string
Checksum int64
Flags int64
Data string
}
Note represents a note in Anki.
type Notetype ¶
type Notetype struct {
ID int64
Name string
Modified time.Time
USN int64
Fields []*Field
Templates []*Template
Config *pb.NotetypeConfig
}
Notetype represents a notetype in Anki.
type Template ¶
type Template struct {
Ordinal int
Name string
Modified time.Time
USN int64
Config *pb.TemplateConfig
}
Template represents a template in a notetype.
func NewTemplate ¶
NewTemplate creates a new template with the given name, question format, and answer format. The ordinal is initialized to -1 and will be set when added to a notetype.