A lightweight Golang interface for ankiconnect. This library depends on Anki and the ankiconnect addon.
- Get Anki deck names.
- Create a new deck in Anki.
- Delete a existing deck from Anki.
- Add a new card to an existing deck in Anki.
go get github.com/atselvan/ankiconnect
Anki should be running in the background with the ankiconnect addon installed for below examples to work.
client := ankiconnect.NewClient()
restErr := client.Ping()
if restErr != nil {
log.Fatal(restErr)
}
client := ankiconnect.NewClient()
decks, restErr := client.Decks.GetAll()
if restErr != nil {
log.Fatal(restErr)
}
fmt.Println(decks)
client := ankiconnect.NewClient()
restErr := client.Decks.Create("New Deck")
if restErr != nil {
log.Fatal(restErr)
}
client := ankiconnect.NewClient()
restErr := client.Decks.Delete("New Deck")
if restErr != nil {
log.Fatal(restErr)
}
client := ankiconnect.NewClient()
note := ankiconnect.Note{
DeckName: "New Deck",
ModelName: "Basic-a39a1",
Fields: ankiconnect.Fields{
Front: "Front data",
Back: "Back data",
},
}
restErr := client.Notes.Add(note)
if restErr != nil {
log.Fatal(restErr)
}
client := ankiconnect.NewClient()
// Get the Note Ids of cards due today
nodeIds, restErr := client.Notes.Get("prop:due=0")
if restErr != nil {
log.Fatal(restErr)
}
// Get the Note data of cards due today
notes, restErr := client.Notes.Get("prop:due=0")
if restErr != nil {
log.Fatal(restErr)
}
client := ankiconnect.NewClient()
// Get the Card Ids of cards due today
nodeIds, restErr := client.Cards.Get("prop:due=0")
if restErr != nil {
log.Fatal(restErr)
}
// Get the Card data of cards due today
notes, restErr := client.Cards.Get("prop:due=0")
if restErr != nil {
log.Fatal(restErr)
}
client := ankiconnect.NewClient()
restErr := client.Sync.Trigger()
if restErr != nil {
log.Fatal(restErr)
}