Skip to content

Latest commit

 

History

History
182 lines (114 loc) · 5.28 KB

README.adoc

File metadata and controls

182 lines (114 loc) · 5.28 KB

Kindle Highlights for the Command Line

Note
THIS IS NOT WORKING CURRENTLY, AS AMAZON CHANGED THEIR SITE

What is this?

The kindle highlights app gives YOU your kindle highlights without the poor interface Amazon has wrapped around YOUR DATA.

If you are like me, you make a lot of highlights while you read ebooks. I mark vocab words, great phrases, and inspirational sections.

The kindle command empowers you to actually DO something with all those highlights you’ve been making on your Kindle and Kindle apps. The app downloads and caches your highlights. You can then get them in various formats like JSON, CSV, and a nice little Markdown format to run through pandoc or Marked app.

Specifically, you can:

  • scrape and parse your kindle highlights and book data

  • keep your highlights stored locally

  • output in JSON format

  • output in CSV format

  • output in Markdown format

  • do sophisticated queries on your data using the kindle console

Future plans:

  • automatic scanning for vocabulary words

  • output in other formats

Installation

gem install kindle

There are a lot of dependencies (including the latest Rails ActiveRecord v5), as this app is intended to provide a lot of conveniences and functionality over other lighter libraries like from our friend @speric! ❤️

Usage:

Warnings and Caveats (HACKER ALERT)

hackers

Let’s talk about passwords and security. Using the kindle command line app gives you the convenience to save your Amazon credentials in a file on your computer. This is probably bad. Don’t do it. You’ve been warned.

Hax0rz will hack.

If, however, you intend to keep your password out of the settings file, you’ll need to pass in the --password=<secret> argument every time. Again: Be Forewarned: Your shell is probably configured by default to save a history of what you type in. For that reason, you should be using something like the zsh option HIST_IGNORE_SPACE to "hide" your most-secretest commands.


Step 1: Initialization

kindle init

First you need to initialize the app with some default and/or customized settings, as well as create the database to store your highlights.

To initialize and save your password and username:

# Option 1
kindle --username="[email protected]" --password="yoursecret" init

OR

To initialize with just a username:

# Option 2
kindle --username="[email protected]" init

OR

Just run the init sub-command without any parameters, knowing you will just have to pass them in later. Every time.

# Option 3
kindle init

Step 2: Fetch your data

kindle highlights update

The update sub-command uses either the passed in credentials or the saved credentials in the settings file and reaches out to Amazon’s Kindle highlights website. It slurps all the highlights (and book info) and saves it in a SQLite3 database in ~/.kindle.

kindle highlights update

The update command will take a while to run, depending on how many highlights you have. Don’t worry if it doesn’t seem to do anything. That’s okay. Trust in the UNIX-way.


Step 3: Output your data

kindle highlights

The highlights command requires a sub-command to generate the appropriate output. Currently the available output formats are: JSON, CSV, and Markdown.

Example with JSON:

# Output in json format and redirect to highlights.json file
kindle highlights json > highlights.json

Example with CSV:

# Output in csv format and redirect to highlights.csv file
kindle highlights csv > highlights.csv

Example with Markdown:

# Output in markdown format and redirect to highlights.md file
kindle highlights markdown > highlights.md

Advanced Topic: The Console

1hbw6

I’ve also included a console command for those of you familiar with Ruby on Rails, irb, etc. Issuing the kindle console command will open a console session with two ActiveRecord objects: Book and Highlight. These are real ActiveRecord v5.0 models pointing to the database of highlights.

Qesb

kindle console examples:

Kindle :) Book.count
=> 45

Kindle :) Highlight.count
=> 587

Kindle :) Highlight.first
=> #<Kindle::Models::Highlight:0x007fd43a50ae90
 id: 1,
 highlight: "riparian",
 amazon_id: nil,
 book_id: 1,
 created_at: 2016-07-01 00:18:32 UTC,
 updated_at: 2016-07-01 00:18:32 UTC>

Kindle :) Book.first
=> #<Kindle::Models::Book:0x007fd43a591800
 id: 1,
 asin: "B004J4WN0I",
 title: "Hounded (with two bonus short stories): The Iron Druid Chronicles, Book One",
 author: "by Kevin Hearne",
 highlight_count: 8,
 created_at: 2016-07-01 00:18:32 UTC,
 updated_at: 2016-07-01 00:18:32 UTC>

Endcap

In case you are too lazy to open the LICENSE file, just FYI this is all MIT licensed.

© 2012-2016 Matt Petty @lodestone