Skip to content

atselvan/ankiconnect

Repository files navigation

ankiconnect

A lightweight Golang interface for ankiconnect. This library depends on Anki and the ankiconnect addon.

Build Release reference Go Report Card codecov Quality Gate Status FOSSA Status License: MIT

Features

  • 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.

Installation

go get github.com/atselvan/ankiconnect

Usage

Anki should be running in the background with the ankiconnect addon installed for below examples to work.

Ping

client := ankiconnect.NewClient()
restErr := client.Ping()
if restErr != nil {
	log.Fatal(restErr)
}

Get Decks

client := ankiconnect.NewClient()
decks, restErr := client.Decks.GetAll()
if restErr != nil {
	log.Fatal(restErr)
}
fmt.Println(decks)

Create Deck

client := ankiconnect.NewClient()
restErr := client.Decks.Create("New Deck")
if restErr != nil {
	log.Fatal(restErr)
}

Delete Deck

client := ankiconnect.NewClient()
restErr := client.Decks.Delete("New Deck")
if restErr != nil {
	log.Fatal(restErr)
}

Create Note

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)
}

Get Notes

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)
}

Get Cards

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)
}

Sync local data to Anki Cloud

client := ankiconnect.NewClient()

restErr := client.Sync.Trigger()
if restErr != nil {
	log.Fatal(restErr)
}

About

A lightweight Golang interface for ankiconnect

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages