Skip to content

Instantly share code, notes, and snippets.

@futtetennista
Last active June 15, 2019 12:32
Show Gist options
  • Save futtetennista/13a306928a74034953c2b74977b8c0f9 to your computer and use it in GitHub Desktop.
Save futtetennista/13a306928a74034953c2b74977b8c0f9 to your computer and use it in GitHub Desktop.
Export Kindle highlights to Anki
#!/usr/bin/env bash
set -euox pipefail
# Go to https://read.amazon.com/notebook and export your highlights as JSON using https://readwise.io/bookcision
#
# Install http://ankiweb.net/ and the https://foosoft.net/projects/anki-connect/index.html extension. Create a simple front-only card in anki, e.g.
# Card template: {{Front}}
# Styling:
# .card {
# font-family: arial;
# font-size: 20px;
# text-align: center;
# color: black;
# background-color: white;
# }
#
# Install https://stedolan.github.io/jq/
#
# ./kindle2anki.sh <path/to/Kindle.Highlights_book.json> 'Books' '"tag1","tag2"'
# Tested on macOS Sierra 10.12.6, jq-1.5
PATH_TO_JSON_HIGHLIGHTS=$1
DECK_NAME=$2
TAGS=$3
cat $PATH_TO_JSON_HIGHLIGHTS | jq --indent 0 'def json2anki(xs): {"action":"addNotes","version":6,"params":{"notes":xs | map({"deckName":'"$DECK_NAME"',"modelName":"Front-only","fields":{"Front":.text | sub("(?<txt>.+),";.txt)},"tags":['"$TAGS"']})}}; json2anki(.highlights)' | xargs -0 -J % curl localhost:8765 -d '%'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment