added a script to list bookcodes by subseries
authorJonathan Blake <jonathan.blake@projectaon.org>
Thu, 22 Feb 2018 23:44:28 +0000 (23:44 +0000)
committerJonathan Blake <jonathan.blake@projectaon.org>
Thu, 22 Feb 2018 23:44:28 +0000 (23:44 +0000)
git-svn-id: https://projectaon.org/data/trunk@2701 f6f3e2d7-ff33-0410-aaf5-b4bee2cdac11

common/scripts/list-bookcodes-by-subseries.sh [new file with mode: 0755]

diff --git a/common/scripts/list-bookcodes-by-subseries.sh b/common/scripts/list-bookcodes-by-subseries.sh
new file mode 100755 (executable)
index 0000000..450520d
--- /dev/null
@@ -0,0 +1,28 @@
+#!/usr/bin/env bash
+#
+# List all bookcodes that match given subseries.
+# 
+# Example:
+#     list-bookcodes-by-subseries.sh lw gs
+
+if [ ! -d "$AONDIR" ]; then
+    >&2 echo "Please set the AONDIR environment variable"
+    exit 1
+fi
+
+book_db="$AONDIR/common/sqlite/bookcodes.db"
+
+for subseries in $@
+do
+    if [[ ! $subseries =~ ^[a-z]+$ ]]; then
+        >&2 echo "invalid subseries"
+        exit 1
+    fi
+
+    sqlite3 -column -noheader "$book_db" <<EOF
+      select book 
+      from bookcodes 
+      where subseries = '$subseries'
+      order by book
+EOF
+done