summaryrefslogtreecommitdiff
path: root/main.go
blob: 7306df2e66050fd4a1561efc41959252748aba5e (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
40
41
42
43
44
// 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)
		}
	}

}