anki-i3blocks

an i3blocks block to display Anki stats
Log | Files | Refs | README | LICENSE

commit 389dde46e84f1284742ae008fd062a32da5a3634
parent 2f3b1c58287715a0e59f9eb7de5385aa8be0783a
Author: Stefan Koch <programming@stefan-koch.name>
Date:   Sun,  4 Jul 2021 18:15:11 +0200

work around exclusive lock issues

Diffstat:
Manki | 9+++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/anki b/anki @@ -9,7 +9,12 @@ fi learning_query="SELECT COUNT(*) FROM cards c JOIN decks d ON c.did = d.id WHERE d.name = '$deck' COLLATE NOCASE AND c.ivl != 0;" all_query="SELECT COUNT(*) FROM cards c JOIN decks d ON c.did = d.id WHERE d.name = '$deck' COLLATE NOCASE;" -learning_count=$(sqlite3 "$ANKI_COLLECTION_PATH" "$learning_query") -all_count=$(sqlite3 "$ANKI_COLLECTION_PATH" "$all_query") +# TODO: Is there really no other way to work around the exclusive lock that +# Anki or AnkiConnect seems to hold than copying the whole database? +tmp_db=/tmp/anki.sqlite3 +cp "$ANKI_COLLECTION_PATH" $tmp_db +learning_count=$(sqlite3 -readonly $tmp_db "$learning_query") +all_count=$(sqlite3 -readonly $tmp_db "$all_query") +rm $tmp_db echo $learning_count/$all_count