blob: f1598bf3865af98328c365df340dded8657d12fa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
// 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)
}
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)
}
}
}
|