项目作者: kyamaguchi

项目描述 :
Scrape information of kindle books and highlights from amazon site
高级语言: Ruby
项目地址: git://github.com/kyamaguchi/kindle_manager.git
创建时间: 2017-03-15T07:47:48Z
项目社区:https://github.com/kyamaguchi/kindle_manager

开源协议:MIT License

下载


KindleManager

Gem Version
CircleCI

Scrape information of kindle books & highlights from amazon site

Fetch Kindle Books information

kindle_manager_fetch

Load books information

kindle_manager_load_books
Recorded with Recordit

Installation

Add this line to your application’s Gemfile:

  1. gem 'kindle_manager'

And then execute:

  1. $ bundle

Or install it yourself as:

  1. $ gem install kindle_manager

Usage

Setup

chromedriver is required. Please download chromedriver and update chromedriver regularly.

Create .env following the instructions of https://github.com/kyamaguchi/amazon_auth

  1. amazon_auth
  2. vi .env

And Dotenv.load or gem 'dotenv-rails' may be required when you use this in your app.

Run

Kindle books list

In console

  1. require 'kindle_manager'
  2. client = KindleManager::Client.new(keep_cookie: true, verbose: true, limit: 1000)
  3. client.fetch_kindle_list
  4. books = client.load_kindle_books
  5. client.quit

Once fetch_kindle_list succeeds, you can load books information of downloaded pages anytime.
(You don’t need to fetch pages with launching browser every time.)

  1. client = KindleManager::Client.new
  2. books = client.load_kindle_books

Example of data

  1. console> pp books.first.to_hash
  2. {"asin"=>"B0026OR2TU",
  3. "title"=>
  4. "Rails Cookbook: Recipes for Rapid Web Development with Ruby (Cookbooks (O'Reilly))",
  5. "tag"=>"Sample",
  6. "author"=>"Rob Orsini",
  7. "date"=>Fri, 17 Mar 2017,
  8. "collection_count"=>0}

Kindle highlights and notes

In console

  1. require 'kindle_manager'
  2. client = KindleManager::Client.new(keep_cookie: true, verbose: true, limit: 10)
  3. client.fetch_kindle_highlights
  4. books = client.load_kindle_highlights

Example of data

  1. console> pp books.first.to_hash
  2. {"asin"=>"B004YW6M6G",
  3. "title"=>
  4. "Design Patterns in Ruby (Adobe Reader) (Addison-Wesley Professional Ruby Series)",
  5. "author"=>"Russ Olsen",
  6. "last_annotated_on"=>Wed, 21 Jun 2017,
  7. "highlights_count"=>8,
  8. "notes_count"=>7,
  9. "highlights_and_notes"=>
  10. [{"location"=>350,
  11. "highlight"=>
  12. "Design Patterns: Elements of Reusable Object-Oriented Software,",
  13. "color"=>"orange",
  14. "note"=>""},
  15. {"location"=>351,
  16. "highlight"=>"\"Gang of Four book\" (GoF)",
  17. "color"=>"yellow",
  18. "note"=>""},
  19. {"location"=>356, "highlight"=>nil, "color"=>nil, "note"=>"note foo"},
  20. ...
  21. {"location"=>385,
  22. "highlight"=>nil,
  23. "color"=>nil,
  24. "note"=>"object oriented"}]}

Options

Limit fetching with number of fetched books: client = KindleManager::Client.new(limit: 100)

Change sleep duration on scrolling (default 3 seconds): client = KindleManager::Client.new(fetching_interval: 5)

Change max scroll attempts (default 20): client = KindleManager::Client.new(max_scroll_attempts: 30)

Renew the directory for downloading: create: true

Options of amazon_auth gem

Firefox: driver: :firefox

Login and password: login: 'xxx', password: 'yyy'

Output debug log: debug: true

TODO

  • Limit the number of fetching books by date

Applications

Applications using this gem

Development

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 tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/kyamaguchi/kindle_manager.

License

The gem is available as open source under the terms of the MIT License.