kindle 0.1.3 → 0.7.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.adoc +44 -0
- data/CODE_OF_CONDUCT.adoc +73 -0
- data/Gemfile +14 -2
- data/LICENSE +1 -1
- data/README.adoc +180 -0
- data/bin/kindle +2 -19
- data/features/highlights.feature +117 -0
- data/features/support/aruba.rb +1 -0
- data/features/support/highlight_steps.rb +13 -0
- data/kindle.gemspec +11 -7
- data/lib/kindle.rb +18 -17
- data/lib/kindle/cli.rb +115 -0
- data/lib/kindle/exports/csv.rb +15 -0
- data/lib/kindle/exports/json.rb +12 -0
- data/lib/kindle/exports/markdown.rb +18 -0
- data/lib/kindle/migrations/base_migration.rb +22 -0
- data/lib/kindle/migrations/initializer.rb +13 -0
- data/lib/kindle/models/book.rb +26 -0
- data/lib/kindle/models/highlight.rb +24 -0
- data/lib/kindle/parser/agent.rb +13 -0
- data/lib/kindle/parser/annotations.rb +130 -0
- data/lib/kindle/remote/book.rb +14 -0
- data/lib/kindle/remote/highlight.rb +12 -0
- data/lib/kindle/settings.rb +51 -0
- data/templates/database.yml +11 -0
- data/test/cli_test.rb +0 -0
- data/test/highlights_test.rb +13 -0
- data/test/kindle_test.rb +17 -0
- metadata +98 -17
- data/.rvmrc +0 -1
- data/Changelog +0 -24
- data/README.md +0 -19
- data/lib/kindle/highlight.rb +0 -13
- data/lib/kindle/highlights_parser.rb +0 -105
- data/lib/kindle/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d76fcf6266ee2a160164f3ca599d53145d5f388f
|
4
|
+
data.tar.gz: ca81d7a57bddd7cc8e81b3e791c5a980630bcf34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48e50e8d8785f1df6bce208a8fb900f1c6626e647555859273dfef0ff2f13d1879dcaee3fc00b1e34297b8f8bc5633d21dd6af368c87e24f7105049c188c15aa
|
7
|
+
data.tar.gz: 52e20c55f7294702607df3af0b77573d35149b0ff5a11d0904440edc93b0f5a5448367a77d0d31df5e5985f091a04afec61c063a653f3dc886eafdafea0e8570
|
data/.gitignore
CHANGED
data/CHANGELOG.adoc
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
= CHANGELOG
|
2
|
+
|
3
|
+
:numbered!:
|
4
|
+
|
5
|
+
== Version 0.7
|
6
|
+
|
7
|
+
* Major refactor and feature additions
|
8
|
+
|
9
|
+
Features:
|
10
|
+
|
11
|
+
* Allow specification of output type
|
12
|
+
* cache results
|
13
|
+
* handle Captcha issue
|
14
|
+
* add proper tests via MiniTest and Cucumber
|
15
|
+
|
16
|
+
== Version 0.2.1
|
17
|
+
|
18
|
+
* Add Code of Conduct
|
19
|
+
* Use Asciidoc for files (README, CODE_OF_CONDUCT, CHANGELOG)
|
20
|
+
|
21
|
+
== Version 0.1.2
|
22
|
+
|
23
|
+
* Also retrieve the highlight annotation_id
|
24
|
+
|
25
|
+
== Version 0.1.1
|
26
|
+
|
27
|
+
* Fix renamed file require
|
28
|
+
|
29
|
+
== Version 0.1.0
|
30
|
+
|
31
|
+
* Confirm the script still works as of 2014-04-10
|
32
|
+
* Make the default command line output semi-colon delimited
|
33
|
+
|
34
|
+
== Version 0.0.3
|
35
|
+
|
36
|
+
* Update headers in requests to get pages of highlights
|
37
|
+
|
38
|
+
== Version 0.0.2
|
39
|
+
|
40
|
+
* Use highline to read command line information
|
41
|
+
|
42
|
+
== Version 0.0.1
|
43
|
+
|
44
|
+
* Initial working version
|
@@ -0,0 +1,73 @@
|
|
1
|
+
= Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
:numbered!:
|
4
|
+
|
5
|
+
== Our Pledge
|
6
|
+
|
7
|
+
In the interest of fostering an open and welcoming environment, we as
|
8
|
+
contributors and maintainers pledge to making participation in our project and
|
9
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
10
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
11
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
12
|
+
orientation.
|
13
|
+
|
14
|
+
== Our Standards
|
15
|
+
|
16
|
+
Examples of behavior that contributes to creating a positive environment
|
17
|
+
include:
|
18
|
+
|
19
|
+
* Using welcoming and inclusive language
|
20
|
+
* Being respectful of differing viewpoints and experiences
|
21
|
+
* Gracefully accepting constructive criticism
|
22
|
+
* Focusing on what is best for the community
|
23
|
+
* Showing empathy towards other community members
|
24
|
+
|
25
|
+
Examples of unacceptable behavior by participants include:
|
26
|
+
|
27
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
28
|
+
advances
|
29
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
30
|
+
* Public or private harassment
|
31
|
+
* Publishing others' private information, such as a physical or electronic
|
32
|
+
address, without explicit permission
|
33
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
34
|
+
professional setting
|
35
|
+
|
36
|
+
== Our Responsibilities
|
37
|
+
|
38
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
39
|
+
behavior and are expected to take appropriate and fair corrective action in
|
40
|
+
response to any instances of unacceptable behavior.
|
41
|
+
|
42
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
43
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
44
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
45
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
46
|
+
threatening, offensive, or harmful.
|
47
|
+
|
48
|
+
== Scope
|
49
|
+
|
50
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
51
|
+
when an individual is representing the project or its community. Examples of
|
52
|
+
representing a project or community include using an official project e-mail
|
53
|
+
address, posting via an official social media account, or acting as an appointed
|
54
|
+
representative at an online or offline event. Representation of a project may be
|
55
|
+
further defined and clarified by project maintainers.
|
56
|
+
|
57
|
+
== Enforcement
|
58
|
+
|
59
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
60
|
+
reported by contacting the project team at matt@kizmeta.com. All
|
61
|
+
complaints will be reviewed and investigated and will result in a response that
|
62
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
63
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
64
|
+
Further details of specific enforcement policies may be posted separately.
|
65
|
+
|
66
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
67
|
+
faith may face temporary or permanent repercussions as determined by other
|
68
|
+
members of the project's leadership.
|
69
|
+
|
70
|
+
== Attribution
|
71
|
+
|
72
|
+
This Code of Conduct is adapted from the link:http://contributor-covenant.org[Contributor Covenant], version 1.4,
|
73
|
+
available at http://contributor-covenant.org/version/1/4
|
data/Gemfile
CHANGED
@@ -1,4 +1,16 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
|
3
|
-
#
|
4
|
-
|
3
|
+
# gem "gli"
|
4
|
+
# gem "sqlite3"
|
5
|
+
# gem "activerecord", "~>5.0.0"
|
6
|
+
# gem "nokogiri"
|
7
|
+
# gem "mechanize"
|
8
|
+
# gem "rainbow"
|
9
|
+
# gem "pry"
|
10
|
+
|
11
|
+
group :test, :development do
|
12
|
+
gem "cucumber", '~> 2'
|
13
|
+
gem "aruba"
|
14
|
+
gem "timecop"
|
15
|
+
gem 'cucumber-timecop', require: false
|
16
|
+
end
|
data/LICENSE
CHANGED
data/README.adoc
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
= Kindle Highlights for the Command Line
|
2
|
+
:author: Matt Petty <matt@kizmeta.com>
|
3
|
+
:copyright: 2016
|
4
|
+
|
5
|
+
:numbered!:
|
6
|
+
|
7
|
+
+++
|
8
|
+
<img src="http://link.nx.is/sWdP.png" style="float:right;width:40%" />
|
9
|
+
+++
|
10
|
+
|
11
|
+
== What is this?
|
12
|
+
|
13
|
+
The kindle highlights app gives **YOU** your kindle highlights without the poor interface Amazon has wrapped around _YOUR DATA_.
|
14
|
+
|
15
|
+
If you are like me, you make a lot of highlights while you read ebooks. I mark vocab words, great phrases, and inspirational sections.
|
16
|
+
|
17
|
+
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.
|
18
|
+
|
19
|
+
**Specifically, you can:**
|
20
|
+
|
21
|
+
* scrape and parse your kindle highlights and book data
|
22
|
+
* keep your highlights stored _**locally**_
|
23
|
+
* output in JSON format
|
24
|
+
* output in CSV format
|
25
|
+
* output in Markdown format
|
26
|
+
* do sophisticated queries on your data using the `kindle console`
|
27
|
+
|
28
|
+
**Future plans:**
|
29
|
+
|
30
|
+
* automatic scanning for vocabulary words
|
31
|
+
* output in other formats
|
32
|
+
|
33
|
+
// TODO. What is this and why do you want to use it?
|
34
|
+
|
35
|
+
== Installation
|
36
|
+
|
37
|
+
```sh
|
38
|
+
gem install kindle
|
39
|
+
```
|
40
|
+
|
41
|
+
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 link:https://github.com/speric/kindle-highlights[libraries] like from our friend link:https://github.com/speric[@speric]! :heart:
|
42
|
+
|
43
|
+
== Usage:
|
44
|
+
|
45
|
+
=== Warnings and Caveats (HACKER ALERT)
|
46
|
+
|
47
|
+
image::http://i.perezhilton.com/wp-content/uploads/2014/12/hackers.gif[width="100%"]
|
48
|
+
|
49
|
+
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.
|
50
|
+
|
51
|
+
Hax0rz *will* hack.
|
52
|
+
|
53
|
+
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 link:http://zsh.sourceforge.net/Doc/Release/Options.html[`HIST_IGNORE_SPACE`] to _"hide"_ your most-secretest commands.
|
54
|
+
|
55
|
+
---
|
56
|
+
|
57
|
+
=== Step 1: Initialization
|
58
|
+
|
59
|
+
==== kindle init
|
60
|
+
|
61
|
+
First you need to initialize the app with some default and/or customized settings, as well as create the database to store your highlights.
|
62
|
+
|
63
|
+
To initialize and save your password and username:
|
64
|
+
|
65
|
+
```sh
|
66
|
+
# Option 1
|
67
|
+
kindle --username=change@your.email --password=yoursecret init
|
68
|
+
```
|
69
|
+
|
70
|
+
**OR**
|
71
|
+
|
72
|
+
To initialize with just a username:
|
73
|
+
|
74
|
+
```sh
|
75
|
+
# Option 2
|
76
|
+
kindle --username=change@your.email init
|
77
|
+
```
|
78
|
+
|
79
|
+
**OR**
|
80
|
+
|
81
|
+
Just run the `init` sub-command without any parameters, knowing you will just have to pass them in later. Every time.
|
82
|
+
|
83
|
+
```sh
|
84
|
+
# Option 3
|
85
|
+
kindle init
|
86
|
+
```
|
87
|
+
|
88
|
+
|
89
|
+
---
|
90
|
+
|
91
|
+
=== Step 2: Fetch your data
|
92
|
+
|
93
|
+
==== kindle update
|
94
|
+
|
95
|
+
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`.
|
96
|
+
|
97
|
+
```sh
|
98
|
+
kindle update
|
99
|
+
```
|
100
|
+
|
101
|
+
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.
|
102
|
+
|
103
|
+
---
|
104
|
+
|
105
|
+
=== Step 3: Output your data
|
106
|
+
|
107
|
+
==== kindle highlights
|
108
|
+
|
109
|
+
The `highlights` sub-command requires a third command to generate the appropriate output. Currently the available output formats are: JSON, CSV, and Markdown.
|
110
|
+
|
111
|
+
Example with JSON:
|
112
|
+
|
113
|
+
```sh
|
114
|
+
# Output in json format and redirect to highlights.json file
|
115
|
+
kindle highlights json > highlights.json
|
116
|
+
```
|
117
|
+
|
118
|
+
Example with CSV:
|
119
|
+
|
120
|
+
|
121
|
+
```sh
|
122
|
+
# Output in csv format and redirect to highlights.csv file
|
123
|
+
kindle highlights csv > highlights.csv
|
124
|
+
```
|
125
|
+
|
126
|
+
Example with Markdown:
|
127
|
+
|
128
|
+
```sh
|
129
|
+
# Output in markdown format and redirect to highlights.md file
|
130
|
+
kindle highlights markdown > highlights.md
|
131
|
+
```
|
132
|
+
|
133
|
+
---
|
134
|
+
|
135
|
+
== Advanced Topic: The Console
|
136
|
+
|
137
|
+
image::http://link.nx.is/1hbw6.png[]
|
138
|
+
|
139
|
+
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.
|
140
|
+
|
141
|
+
image:http://link.nx.is/Qesb.png[width="100%"]
|
142
|
+
|
143
|
+
`kindle console` examples:
|
144
|
+
|
145
|
+
```ruby
|
146
|
+
|
147
|
+
Kindle :) Book.count
|
148
|
+
=> 45
|
149
|
+
|
150
|
+
Kindle :) Highlight.count
|
151
|
+
=> 587
|
152
|
+
|
153
|
+
Kindle :) Highlight.first
|
154
|
+
=> #<Kindle::Models::Highlight:0x007fd43a50ae90
|
155
|
+
id: 1,
|
156
|
+
highlight: "riparian",
|
157
|
+
amazon_id: nil,
|
158
|
+
book_id: 1,
|
159
|
+
created_at: 2016-07-01 00:18:32 UTC,
|
160
|
+
updated_at: 2016-07-01 00:18:32 UTC>
|
161
|
+
|
162
|
+
Kindle :) Book.first
|
163
|
+
=> #<Kindle::Models::Book:0x007fd43a591800
|
164
|
+
id: 1,
|
165
|
+
asin: "B004J4WN0I",
|
166
|
+
title: "Hounded (with two bonus short stories): The Iron Druid Chronicles, Book One",
|
167
|
+
author: "by Kevin Hearne",
|
168
|
+
highlight_count: 8,
|
169
|
+
created_at: 2016-07-01 00:18:32 UTC,
|
170
|
+
updated_at: 2016-07-01 00:18:32 UTC>
|
171
|
+
|
172
|
+
```
|
173
|
+
|
174
|
+
|
175
|
+
== Endcap
|
176
|
+
|
177
|
+
In case you are too lazy to open the LICENSE file, just FYI this is all MIT licensed.
|
178
|
+
|
179
|
+
|
180
|
+
(C) 2012-2016 Matt Petty link:https://github.com/lodestone[@lodestone]
|
data/bin/kindle
CHANGED
@@ -1,21 +1,4 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
2
|
require_relative "../lib/kindle"
|
4
|
-
|
5
|
-
|
6
|
-
login = ask("Enter your Amazon.com username: ") { |q| q.echo = true } unless login = ARGV[0]
|
7
|
-
passwd = ask("Enter your Amazon.com password (This is not stored): ") { |q| q.echo = "*" }
|
8
|
-
|
9
|
-
begin
|
10
|
-
k = Kindle::Highlights.new(:login => login, :password => passwd)
|
11
|
-
puts "Getting your kindle highlights..."
|
12
|
-
highlights = k.fetch_highlights # TODO: Pass in something to bide our time
|
13
|
-
# TODO: Multiple output formats. CSV, JSON, Pretty, HTML?
|
14
|
-
highlights.each do |highlight|
|
15
|
-
puts "#{highlight.asin};#{highlight.title};#{highlight.author};#{highlight.highlight}"
|
16
|
-
end
|
17
|
-
rescue => ex
|
18
|
-
# TODO Actually handle this!
|
19
|
-
puts ex
|
20
|
-
puts "Crud, something went wrong..."
|
21
|
-
end
|
3
|
+
require_relative "../lib/kindle/cli"
|
4
|
+
# Nothing to see here...
|
@@ -0,0 +1,117 @@
|
|
1
|
+
Feature: Kindle Highlights
|
2
|
+
|
3
|
+
In order to make highlighting in ebooks more useful
|
4
|
+
As an Amazon user who highlights content via Kindle or Kindle app
|
5
|
+
I want to get and interact with my kindle highlights via the command line
|
6
|
+
|
7
|
+
Scenario: Default run without parameters should show help
|
8
|
+
Given I successfully run `kindle`
|
9
|
+
Then the output should contain:
|
10
|
+
"""
|
11
|
+
kindle [global options] command [command options] [arguments...]
|
12
|
+
"""
|
13
|
+
|
14
|
+
Scenario: When calling help
|
15
|
+
Given I successfully run `kindle help`
|
16
|
+
Then the output should contain:
|
17
|
+
"""
|
18
|
+
kindle [global options] command [command options] [arguments...]
|
19
|
+
"""
|
20
|
+
|
21
|
+
Scenario: `kindle init`
|
22
|
+
|
23
|
+
Scenario: `kindle update`
|
24
|
+
|
25
|
+
Scenario: `kindle highlights json` should do something
|
26
|
+
Given time is frozen
|
27
|
+
And a database exists
|
28
|
+
And a file named "~/.kindle/kindlerc.yml" with:
|
29
|
+
"""
|
30
|
+
---
|
31
|
+
:version: false
|
32
|
+
:help: false
|
33
|
+
:username: me@my.email
|
34
|
+
:password: secret
|
35
|
+
:domain: amazon.com
|
36
|
+
commands:
|
37
|
+
:_doc: {}
|
38
|
+
:initdb: {}
|
39
|
+
:init: {}
|
40
|
+
:highlights:
|
41
|
+
commands:
|
42
|
+
:update: {}
|
43
|
+
:json: {}
|
44
|
+
:csv: {}
|
45
|
+
:markdown: {}
|
46
|
+
:console: {}
|
47
|
+
"""
|
48
|
+
When I run `kindle highlights json`
|
49
|
+
Then the output should match:
|
50
|
+
"""
|
51
|
+
[.*\"Reach for enlightenment".*"Zen".*]
|
52
|
+
"""
|
53
|
+
And the features should all pass
|
54
|
+
|
55
|
+
Scenario: `kindle highlights csv`
|
56
|
+
Given time is frozen
|
57
|
+
And a database exists
|
58
|
+
And a file named "~/.kindle/kindlerc.yml" with:
|
59
|
+
"""
|
60
|
+
---
|
61
|
+
:version: false
|
62
|
+
:help: false
|
63
|
+
:username: me@my.email
|
64
|
+
:password: secret
|
65
|
+
:domain: amazon.com
|
66
|
+
commands:
|
67
|
+
:_doc: {}
|
68
|
+
:initdb: {}
|
69
|
+
:init: {}
|
70
|
+
:highlights:
|
71
|
+
commands:
|
72
|
+
:update: {}
|
73
|
+
:json: {}
|
74
|
+
:csv: {}
|
75
|
+
:markdown: {}
|
76
|
+
:console: {}
|
77
|
+
"""
|
78
|
+
When I run `kindle highlights csv`
|
79
|
+
Then the output should match:
|
80
|
+
"""
|
81
|
+
.*"Reach for enlightenment","Zen",.*
|
82
|
+
"""
|
83
|
+
And the features should all pass
|
84
|
+
|
85
|
+
Scenario: `kindle highlights markdown`
|
86
|
+
Given time is frozen
|
87
|
+
And a database exists
|
88
|
+
And a file named "~/.kindle/kindlerc.yml" with:
|
89
|
+
"""
|
90
|
+
---
|
91
|
+
:version: false
|
92
|
+
:help: false
|
93
|
+
:username: me@my.email
|
94
|
+
:password: secret
|
95
|
+
:domain: amazon.com
|
96
|
+
commands:
|
97
|
+
:_doc: {}
|
98
|
+
:initdb: {}
|
99
|
+
:init: {}
|
100
|
+
:highlights:
|
101
|
+
commands:
|
102
|
+
:update: {}
|
103
|
+
:json: {}
|
104
|
+
:csv: {}
|
105
|
+
:markdown: {}
|
106
|
+
:console: {}
|
107
|
+
"""
|
108
|
+
When I run `kindle highlights markdown`
|
109
|
+
Then the output should match:
|
110
|
+
"""
|
111
|
+
### Zen by Monk
|
112
|
+
|
113
|
+
> Reach for enlightenment
|
114
|
+
"""
|
115
|
+
And the features should all pass
|
116
|
+
|
117
|
+
Scenario: `kindle console`
|