// This program looks up words fromm Wiktionary, and creates Anki flashcards // from them. package main import ( "database/sql" "flag" "log" "net/http" "time" tea "github.com/charmbracelet/bubbletea" _ "github.com/mattn/go-sqlite3" ) func main() { rawDict := flag.String("rawDictionary", "raw-wiktextract-data.jsonl", "Path to the raw wiktionary data. You can get this by downloading and unzipping https://kaikki.org/frwiktionary/raw-wiktextract-data.jsonl.gz (for French).") dict := flag.String("dictionary", "dictionary.sqlite3", "Path to the parsed dictionary data. This will be generated from rawDictionary.") deckName := flag.String("deck", "", "Name of the deck where new Anki cards will be created.") modelName := flag.String("model", "", "Name of the card type ('model') for new Anki cards.") apiURL := flag.String("apiURL", "http://localhost:8765", "Base URL to access the anki-connect plugin API.") initialWord := flag.String("initialWord", "", "Optional: first word to look up on program launch.") flag.Parse() if *dict == "" { log.Fatal("The -dictionary flag cannot be an empty string. (If not provided, it defaults to dictionary.sqlite3.)") } if *rawDict == "" { log.Fatal("The -rawDictionary flag cannot be an empty string. (If not provided, it defaults to aw-wiktextract-data.jsonl.)") } if *deckName == "" { log.Fatal("The -deck flag must be provided (name of the deck where Anki cards will be created).") } if *modelName == "" { log.Fatal("The -model flag must be provided. This is the name of the card type ('model') for any Anki cards created by this program. This appears under 'Type' on the dialog for creating new cards in Anki.") } db, err := sql.Open("sqlite3", *dict) if err != nil { log.Fatalf("Failed to create or open dictionary at '%s': %s", *dict, err) } defer db.Close() err = setupDatabase(*rawDict, db) if err != nil { log.Fatalf("Failed to set up database: %s", err) } c := http.DefaultClient c.Timeout = 5 * time.Second p := tea.NewProgram(initialModel(c, db, *apiURL, *deckName, *modelName, *initialWord)) if _, err := p.Run(); err != nil { log.Fatalf("Unexpected error encountered while running program: %s", err) } }