Fetch your Kindle Highlights along with their context using the Selenium Webdriver
Install the gem and add to the application's Gemfile by executing:
$ bundle add kindle-notebook
If bundler is not being used to manage dependencies, install the gem by executing:
$ gem install kindle-notebook
You can either create a .env
file and add your credentials, the default values will be fetched from this file, or configure the gem, for example in an initializer file.
KindleNotebook.configure do |config|
config.url = "https://read.amazon.com/"
config.login = ENV["AMAZON_EMAIL"]
config.password = ENV["AMAZON_PASSWORD"]
config.selenium_driver = :firefox
config.headless_mode = false
config.min_highlight_words = 1
config.max_highlight_words = 3
end
The configuration options min_highlight_words
and max_highlight_words
determine the range for a highlight's word count. Highlights with a word count outside this range will not be considered will be filtered out.
Sign in:
client = KindleNotebook::Client.new
client.sign_in
Get the highlights from a book:
books = client.books
book = books.first
book.fetch_highlights
book.highlights
To write to a CSV file:
book.to_csv_file # => "Docker: A Project-Based Approach to Learning - Cannon, Jason.csv"
Book:
#<KindleNotebook::Book:0x00007f0847c4e388
@asin="B09FJ3411G",
@author="Cannon, Jason",
@highlights=[#<KindleNotebook::Highlight:0x00007f46959d61f0 @book_asin="B09FJ3411G", ...],
@highlights_count=13,
@title="Docker: A Project-Based Approach to Learning">
Highlight:
#<KindleNotebook::Highlight:0x00007f46959d61f0
@book_asin="B09FJ3411G",
@context="If you get stuck, the logging component of systemd, called journald, can also help.",
@page="120",
@raw_context="used, for example. If you get stuck, the logging component of systemd, called journald, can also help. This journald command displays the last 20 entries in the",
@raw_text="journald,",
@text="journald">
Book CSV:
text,page,context,book_asin,raw_text,raw_context
journald,120,"If you get stuck, the logging component of systemd, called journald, can also help.",B09FJ3411G,"journald,","used, for example. If you get stuck, the logging component of systemd, called journald, can also help. This journald command displays the last 20 entries in the"
swarm,225,"Docker Swarm In this chapter, you're going to learn how to create and use a Docker",B09FJ3411G,swarm.,"Docker Swarm In this chapter, you're going to learn how to create and use a Docker"
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and the created tag, and push the .gem
file to rubygems.org.
This gem is using puffing-billy for testing which needs the geckodriver executable. It can be installed with:
$ sudo apt-get install firefox-geckodriver # or
$ brew install geckodriver
The executable should be in your PATH
, if it is not you can run the following command (please adapt the location of the geckodriver executable with yours):
$ echo 'export PATH=$PATH:/home/user/.cache/selenium/geckodriver/linux64/0.33.0' >> ~/.zshrc
Bug reports and pull requests are welcome on GitHub at https://github.com/b1anca/kindle-notebook. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the KindleNotebook project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.