kindle-notebook 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +11 -4
- data/kindle-notebook.gemspec +44 -0
- data/lib/kindle-notebook.rb +1 -21
- data/lib/kindle_notebook/amazon_auth.rb +38 -21
- data/lib/kindle_notebook/book.rb +1 -2
- data/lib/kindle_notebook/client.rb +55 -11
- data/lib/kindle_notebook/highlights.rb +3 -2
- data/lib/kindle_notebook/version.rb +1 -1
- metadata +3 -4
- data/kindle_notebook-0.2.0.gem +0 -0
- data/kindle_notebook-0.2.1.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2140c0eb8f9baa719a922a97273ec8ded43b91e06b426b591060cf3c748d7b2a
|
4
|
+
data.tar.gz: 02f8eb3c8769aaaa367f67a470817f0d9898fc5c48bcefd564ef5fdf63c1f174
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25872df3af96a21ddc6452112483d3010a6c4e3c6668aa684ac3e706baff891bd01786275de7489b389bd120bd1aaecf9df87eaf4354dfed308cd59d8163b383
|
7
|
+
data.tar.gz: 9425897ec0a94e74774d3c81967ee10bb547e4292b116c88613675845111e418a2ebc182a7b7c01e3ad5b711fa0fbc1c6bc8279c2a78b0ee533d3cddf851f83d
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -20,10 +20,17 @@ $ gem install kindle-notebook
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
|
23
|
+
Sign in:
|
24
24
|
```rb
|
25
|
-
|
26
|
-
|
25
|
+
client = KindleNotebook::Client.new
|
26
|
+
client.sign_in
|
27
|
+
```
|
28
|
+
|
29
|
+
Get the highlights from a book:
|
30
|
+
```rb
|
31
|
+
books = client.books
|
32
|
+
book = books.first
|
33
|
+
book.fetch_highlights
|
27
34
|
book.highlights
|
28
35
|
```
|
29
36
|
|
@@ -59,7 +66,7 @@ Highlight:
|
|
59
66
|
Book CSV:
|
60
67
|
```csv
|
61
68
|
text,page,context,book_asin,raw_text,raw_context
|
62
|
-
journald,120
|
69
|
+
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"
|
63
70
|
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"
|
64
71
|
```
|
65
72
|
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/kindle_notebook/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "kindle-notebook"
|
7
|
+
spec.version = KindleNotebook::VERSION
|
8
|
+
spec.authors = ["Bianca Vieira"]
|
9
|
+
spec.email = ["bncvr@outlook.com"]
|
10
|
+
|
11
|
+
spec.summary = "Kindle Notebook"
|
12
|
+
spec.description = "Fetch your Kindle Highlights along with their context using the Selenium Webdriver"
|
13
|
+
spec.homepage = "https://github.com/b1anca/kindle-notebook"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.6.0"
|
16
|
+
|
17
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
|
18
|
+
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/b1anca/kindle-notebook"
|
21
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(__dir__) do
|
26
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
|
28
|
+
end
|
29
|
+
end
|
30
|
+
spec.bindir = "exe"
|
31
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ["lib"]
|
33
|
+
|
34
|
+
# Uncomment to register a new dependency of your gem
|
35
|
+
spec.add_dependency "capybara", "~> 3.39"
|
36
|
+
spec.add_dependency "capybara-sessionkeeper", "~> 0.2.0"
|
37
|
+
spec.add_dependency "selenium-webdriver", "~> 4.9"
|
38
|
+
|
39
|
+
spec.add_development_dependency "dotenv", "~> 2.8", ">= 2.8.1"
|
40
|
+
spec.add_development_dependency "pry", "~> 0.14.2"
|
41
|
+
|
42
|
+
# For more information and examples about making a new gem, check out our
|
43
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
44
|
+
end
|
data/lib/kindle-notebook.rb
CHANGED
@@ -17,32 +17,12 @@ require_relative "kindle_notebook/version"
|
|
17
17
|
module KindleNotebook
|
18
18
|
class Error < StandardError; end
|
19
19
|
|
20
|
-
Capybara.register_driver :chrome do |app|
|
21
|
-
options = Selenium::WebDriver::Chrome::Options.new
|
22
|
-
options.add_argument("--headless") if configuration.headless_mode
|
23
|
-
options.add_argument("--disable-gpu")
|
24
|
-
options.add_argument("--no-sandbox")
|
25
|
-
|
26
|
-
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
|
27
|
-
end
|
28
|
-
|
29
|
-
Capybara.register_driver :firefox do |app|
|
30
|
-
options = Selenium::WebDriver::Firefox::Options.new
|
31
|
-
options.add_argument("--headless") if configuration.headless_mode
|
32
|
-
|
33
|
-
Capybara::Selenium::Driver.new(app, browser: :firefox, options: options)
|
34
|
-
end
|
35
|
-
|
36
20
|
class << self
|
37
|
-
attr_accessor :configuration
|
21
|
+
attr_accessor :configuration, :session
|
38
22
|
|
39
23
|
def configure
|
40
24
|
self.configuration ||= Configuration.new
|
41
25
|
yield(configuration)
|
42
26
|
end
|
43
|
-
|
44
|
-
def session
|
45
|
-
@session ||= AmazonAuth.new.sign_in
|
46
|
-
end
|
47
27
|
end
|
48
28
|
end
|
@@ -2,52 +2,69 @@
|
|
2
2
|
|
3
3
|
module KindleNotebook
|
4
4
|
class AmazonAuth
|
5
|
-
def initialize
|
6
|
-
@
|
5
|
+
def initialize(email:, password:)
|
6
|
+
@email = email
|
7
|
+
@password = password
|
7
8
|
end
|
8
9
|
|
9
10
|
def sign_in
|
10
|
-
|
11
|
-
|
11
|
+
session.visit(KindleNotebook.configuration.url)
|
12
|
+
if valid_cookies?
|
13
|
+
puts 'Session restored!'
|
14
|
+
return session
|
15
|
+
end
|
12
16
|
|
13
17
|
submit_sign_in_form
|
14
|
-
|
15
|
-
|
18
|
+
submit_otp_form if mfa?
|
19
|
+
session.save_cookies
|
20
|
+
puts "You're signed in!"
|
16
21
|
end
|
17
22
|
|
18
23
|
private
|
19
24
|
|
20
|
-
attr_reader :
|
25
|
+
attr_reader :email, :password
|
26
|
+
|
27
|
+
def session
|
28
|
+
KindleNotebook.session
|
29
|
+
end
|
21
30
|
|
22
31
|
def valid_cookies?
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
32
|
+
session.find_latest_cookie_file
|
33
|
+
session.restore_cookies
|
34
|
+
session.refresh
|
35
|
+
session.has_current_path?("/kindle-library")
|
27
36
|
end
|
28
37
|
|
29
38
|
def submit_otp_form
|
30
39
|
print "Enter OTP: "
|
31
|
-
|
32
|
-
|
33
|
-
|
40
|
+
otp = gets.chomp
|
41
|
+
session.fill_in("auth-mfa-otpcode", with: otp)
|
42
|
+
session.first("#auth-signin-button").click
|
43
|
+
check_errors
|
34
44
|
end
|
35
45
|
|
36
46
|
def submit_sign_in_form
|
37
|
-
|
47
|
+
session.click_button("Sign in with your account", match: :first)
|
38
48
|
fill_in_credentials
|
39
|
-
|
40
|
-
|
41
|
-
|
49
|
+
session.check("rememberMe")
|
50
|
+
session.first("#signInSubmit").click
|
51
|
+
check_errors
|
42
52
|
end
|
43
53
|
|
44
54
|
def fill_in_credentials
|
45
|
-
|
46
|
-
|
55
|
+
session.fill_in("ap_email", with: email)
|
56
|
+
session.fill_in("ap_password", with: password)
|
47
57
|
end
|
48
58
|
|
49
59
|
def mfa?
|
50
|
-
|
60
|
+
session.current_path.match?(%r{ap/mfa})
|
61
|
+
end
|
62
|
+
|
63
|
+
def check_errors
|
64
|
+
return unless session.all("h4", text: "There was a problem").any?
|
65
|
+
|
66
|
+
message = session.all("div", class: "a-alert-content").map(&:text).join(", ") || "There was a problem"
|
67
|
+
raise StandardError, message
|
51
68
|
end
|
52
69
|
end
|
53
70
|
end
|
data/lib/kindle_notebook/book.rb
CHANGED
@@ -31,8 +31,7 @@ module KindleNotebook
|
|
31
31
|
|
32
32
|
def open_book
|
33
33
|
session.visit(KindleNotebook.configuration.url) unless session.has_selector?("p", text: title)
|
34
|
-
session.find("p", text: title).click
|
35
|
-
sleep 3 # book might take a bit to load
|
34
|
+
session.find("p", text: title, wait: 3).click
|
36
35
|
end
|
37
36
|
end
|
38
37
|
end
|
@@ -1,20 +1,64 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module KindleNotebook
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
class Client
|
5
|
+
attr_reader :session
|
6
|
+
|
7
|
+
def initialize(email: KindleNotebook.configuration.login,
|
8
|
+
password: KindleNotebook.configuration.password,
|
9
|
+
headless_mode: KindleNotebook.configuration.headless_mode,
|
10
|
+
selenium_driver: KindleNotebook.configuration.selenium_driver)
|
11
|
+
@email = email
|
12
|
+
@password = password
|
13
|
+
@headless_mode = headless_mode
|
14
|
+
@selenium_driver = selenium_driver.to_sym
|
15
|
+
@session = new_capybara_session
|
16
|
+
end
|
17
|
+
|
18
|
+
def books
|
19
|
+
@books ||= fetch_books
|
20
|
+
end
|
21
|
+
|
22
|
+
def sign_in
|
23
|
+
AmazonAuth.new(password: password, email: email).sign_in
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
attr_reader :email, :password, :headless_mode, :selenium_driver
|
29
|
+
|
30
|
+
def fetch_books
|
31
|
+
session.find("ul#cover").all("li").map do |element|
|
32
|
+
Book.new(author: element.find("div", id: /author-/).text,
|
33
|
+
title: element.find("div", id: /title-/).text,
|
34
|
+
asin: element.find("div", match: :first)["data-asin"])
|
8
35
|
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def new_capybara_session
|
39
|
+
chrome_driver
|
40
|
+
firefox_driver
|
41
|
+
|
42
|
+
KindleNotebook.session = Capybara::Session.new(selenium_driver)
|
43
|
+
end
|
44
|
+
|
45
|
+
def firefox_driver
|
46
|
+
Capybara.register_driver :firefox do |app|
|
47
|
+
options = Selenium::WebDriver::Firefox::Options.new
|
48
|
+
options.add_argument("--headless") if headless_mode
|
49
|
+
|
50
|
+
Capybara::Selenium::Driver.new(app, browser: :firefox, options: options)
|
51
|
+
end
|
52
|
+
end
|
9
53
|
|
10
|
-
|
54
|
+
def chrome_driver
|
55
|
+
Capybara.register_driver :chrome do |app|
|
56
|
+
options = Selenium::WebDriver::Chrome::Options.new
|
57
|
+
options.add_argument("--headless") if headless_mode
|
58
|
+
options.add_argument("--disable-gpu")
|
59
|
+
options.add_argument("--no-sandbox")
|
11
60
|
|
12
|
-
|
13
|
-
KindleNotebook.session.find("ul#cover").all("li").map do |element|
|
14
|
-
Book.new(author: element.find("div", id: /author-/).text,
|
15
|
-
title: element.find("div", id: /title-/).text,
|
16
|
-
asin: element.find("div", match: :first)["data-asin"])
|
17
|
-
end
|
61
|
+
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
|
18
62
|
end
|
19
63
|
end
|
20
64
|
end
|
@@ -29,7 +29,8 @@ module KindleNotebook
|
|
29
29
|
|
30
30
|
# fetch all highlights (without context) from notebook
|
31
31
|
def notebook_highlights
|
32
|
-
|
32
|
+
notebook_content = session.all("div", class: "notebook-content")
|
33
|
+
content = notebook_content.any? ? notebook_content.first.all("ion-item") : []
|
33
34
|
puts "#{content.count} highlights in this book \n"
|
34
35
|
book.highlights_count = content.count
|
35
36
|
content.map { |h| parse_notebook_highlight(h) }
|
@@ -82,7 +83,7 @@ module KindleNotebook
|
|
82
83
|
end
|
83
84
|
|
84
85
|
def show_toolbar
|
85
|
-
session.first(:xpath, "//ion-header", wait:
|
86
|
+
session.first(:xpath, "//ion-header", wait: 3).hover
|
86
87
|
end
|
87
88
|
|
88
89
|
def search_highlight_context(text, page)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kindle-notebook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bianca Vieira
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|
@@ -103,8 +103,7 @@ files:
|
|
103
103
|
- LICENSE.txt
|
104
104
|
- README.md
|
105
105
|
- Rakefile
|
106
|
-
-
|
107
|
-
- kindle_notebook-0.2.1.gem
|
106
|
+
- kindle-notebook.gemspec
|
108
107
|
- lib/kindle-notebook.rb
|
109
108
|
- lib/kindle_notebook/amazon_auth.rb
|
110
109
|
- lib/kindle_notebook/book.rb
|
data/kindle_notebook-0.2.0.gem
DELETED
Binary file
|
data/kindle_notebook-0.2.1.gem
DELETED
Binary file
|