// This program looks up words fromm Wiktionary, and creates Anki flashcards // from them. package main import ( "database/sql" "log" _ "github.com/mattn/go-sqlite3" ) const rawDictionary = "/home/david/work/french-wiktionary-flashcards/raw-wiktextract-data.jsonl" const dictionary = "/home/david/work/french-wiktionary-flashcards/raw-wiktextract-data.sqlite3" func main() { db, err := sql.Open("sqlite3", dictionary) if err != nil { log.Fatalf("opening DB '%s': %s", dictionary, err) } defer db.Close() _, err = db.Exec("create table IF NOT EXISTS words (word text not null, definition text);") if err != nil { log.Fatalf("creating table: %s", err) } _, err = db.Exec("PRAGMA synchronous = OFF;") if err != nil { log.Fatalf("setting risky writes: %s", err) } row := db.QueryRow(`SELECT count(*) as count from words`) var count int err = row.Scan(&count) if err != nil { log.Fatalf("counting rows: %s", err) } if count == 0 { if err = readDictionary(db); err != nil { log.Fatalf("failed to prepare dictionary: %s", err) } } }