URI: 
       Initial commit - bookdarts - Extract KOReader generated highlights and publish them in a variety of formats↵
   DIR Log
   DIR Files
   DIR Refs
       ---
   DIR commit 2cb9ba25d0eb8d25575fa0b5c8912acf08f5db4d
  HTML Author: Scarlett McAllister <no+reply@roygbyte.com>
       Date:   Sat, 16 Sep 2023 12:28:45 -0300
       
       Initial commit
       
       Diffstat:
         A bookdarts.sh                        |      45 +++++++++++++++++++++++++++++++
         A export-from-device.sh               |      23 +++++++++++++++++++++++
         A highlights.json                     |      44 +++++++++++++++++++++++++++++++
       
       3 files changed, 112 insertions(+), 0 deletions(-)
       ---
   DIR diff --git a/bookdarts.sh b/bookdarts.sh
       @@ -0,0 +1,45 @@
       +#!/bin/sh
       +
       +log() {
       +    printf "$1\n"
       +}
       +
       +nth_element() {
       +    cat "$HIGHLIGHTS_FILE" | jq .documents.[$1]
       +    return 1
       +}
       +
       +get_document_attribute() {
       +    # Given a document element, function evaluates
       +    # to the given attribute.
       +    #     $1: document as JSON object
       +    #     $2: name of the attribute.
       +    #     $3: index of attribute.
       +    case $2 in
       +        title) printf "$1" | jq .title ;;
       +        author) cat "$1" | jq .author ;;
       +        file) cat "$1" | jq .file ;;
       +        entry) cat "$1" | jq .entries[$3] ;;
       +        *) ;;
       +    esac    
       +}
       +
       +get_entry_attribute() {
       +    case $1 in
       +        text) jq .text ;;
       +        chapter) jq .chapter ;;
       +        sort) jq .sort ;;
       +        drawer) jq .drawer ;;
       +        time) jq .time ;;
       +    esac
       +}
       +
       +HIGHLIGHTS_FILE="highlights.json"
       +DOCUMENTS_COUNT=$(cat "$HIGHLIGHTS_FILE" | jq .documents.[].title | wc -l)
       +log "Found $DOCUMENTS_COUNT documents."
       +
       +INDEX=0
       +while [ $(( $INDEX < $DOCUMENTS_COUNT )) = 1 ]; do
       +    get_document_attribute "$(nth_element $INDEX)" title
       +    INDEX=$(( $INDEX + 1 ))
       +done
   DIR diff --git a/export-from-device.sh b/export-from-device.sh
       @@ -0,0 +1,23 @@
       +#!/bin/sh
       +
       +# Dependencies: rsync
       +
       +BOOKDARTS_DIR=$PWD
       +DEVICE_DIR=/media/kobo
       +HIGHLIGHTS_DIR=/.adds/koreader/clipboard
       +HIGHLIGHTS_FILENAME_REGEX=".*-all-books.json"
       +HIGHLIGHTS_FILE=$(ls -a "$DEVICE_DIR/$HIGHLIGHTS_DIR" | sort | grep -E "$HIGHLIGHTS_FILENAME_REGEX" | head -n 1)
       +
       +if [ -z "$HIGHLIGHTS_FILE" ]; then
       +    printf "Could not find highlights file. Exiting..."
       +    exit 1
       +fi
       +
       +printf "Found highlights file: %s" "$HIGHLIGHTS_DIR/$HIGHLIGHTS_FILE\n"
       +
       +if [ ! -r "$HIGHLIGHTS_DIR/HIGHLIGHTS_FILE" ]; then
       +    printf "Could not read from file. Exiting..."
       +    exit 1
       +fi
       +
       +cp "$HIGHLIGHTS_DIR/$HIGHLIGHTS_FILE" "$BOOKDARTS_DIR"
   DIR diff --git a/highlights.json b/highlights.json
       @@ -0,0 +1,44 @@
       +{
       +    "version": "json/1.0.0",
       +    "created_on": 1694745657,
       +    "documents": [
       +        {
       +            "entries": [
       +                {
       +                    "time": 1694745644,
       +                    "sort": "highlight",
       +                    "text": "registered trademarks",
       +                    "drawer": "lighten",
       +                    "chapter": "Copyright",
       +                    "page": 2
       +                }
       +            ],
       +            "file": "/home/roygbyte/Link,Kelly-BlackDogWhiteCat.epub",
       +            "title": "White Cat, Black Dog: Stories",
       +            "author": "Kelly Link"
       +        },
       +        {
       +            "entries": [
       +                {
       +                    "time": 1694745025,
       +                    "sort": "highlight",
       +                    "text": "narrative",
       +                    "drawer": "lighten",
       +                    "chapter": "Praise for Heavier Than Heaven",
       +                    "page": 3
       +                },
       +                {
       +                    "time": 1694745031,
       +                    "sort": "highlight",
       +                    "text": "someone writes a book that is more daring in its psychological and social",
       +                    "drawer": "lighten",
       +                    "chapter": "Praise for Heavier Than Heaven",
       +                    "page": 3
       +                }
       +            ],
       +            "file": "/home/roygbyte/Downloads/Charles R. Cross - Heavier Than Heaven_ A Biography of Kurt Cobain-Hyperion (2002).epub",
       +            "title": "Heavier Than Heaven",
       +            "author": "Charles R. Cross"
       +        }
       +    ]
       +}