klipbook 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +6 -0
- data/Gemfile.lock +2 -2
- data/README.md +15 -7
- data/klipbook.gemspec +4 -3
- data/lib/klipbook.rb +1 -1
- data/lib/klipbook/fetcher.rb +1 -1
- data/lib/klipbook/sources/amazon_site/{scraper.rb → site_scraper.rb} +21 -19
- data/lib/klipbook/version.rb +1 -1
- data/spec/lib/klipbook/fetcher_spec.rb +2 -2
- metadata +5 -4
data/CHANGELOG.txt
ADDED
data/Gemfile.lock
CHANGED
@@ -16,7 +16,7 @@ GEM
|
|
16
16
|
gherkin (~> 2.11.0)
|
17
17
|
json (>= 1.4.6)
|
18
18
|
diff-lcs (1.1.3)
|
19
|
-
domain_name (0.5.
|
19
|
+
domain_name (0.5.6)
|
20
20
|
unf (~> 0.0.3)
|
21
21
|
ffi (1.1.5)
|
22
22
|
gherkin (2.11.2)
|
@@ -51,7 +51,7 @@ GEM
|
|
51
51
|
method_source (0.8)
|
52
52
|
mime-types (1.19)
|
53
53
|
net-http-digest_auth (1.2.1)
|
54
|
-
net-http-persistent (2.
|
54
|
+
net-http-persistent (2.8)
|
55
55
|
nokogiri (1.5.5)
|
56
56
|
ntlm-http (0.1.1)
|
57
57
|
pry (0.9.10)
|
data/README.md
CHANGED
@@ -18,8 +18,8 @@ canonical source and will contain all of your notes and highlights from across a
|
|
18
18
|
your Kindle devices and applications. Currently the Amazon highlights site only shows
|
19
19
|
clippings for books you've purchased on Amazon.
|
20
20
|
|
21
|
-
If your books are personal documents and you've read them on your
|
22
|
-
itself then you should use the file from that device as a source i.e.
|
21
|
+
If your books are personal documents and you've read them on your Kindle device
|
22
|
+
itself then you should use the file from that device as a source i.e. your Kindle
|
23
23
|
device only keeps clippings that you made directly on it.
|
24
24
|
|
25
25
|
## How does it work?
|
@@ -40,23 +40,28 @@ Then write out a list of your clippings via:
|
|
40
40
|
$ klipbook collate "file:My Clippings.txt"
|
41
41
|
|
42
42
|
This command will write the collected clippings for the latest annotated book to a file in the current
|
43
|
-
directory. You can override the output directory with the `--output-dir`
|
43
|
+
directory. You can override the output directory with the `--output-dir` switch.
|
44
|
+
|
45
|
+
You can also specify a maximum count of books you'd like collated with the `--num-books` switch.
|
44
46
|
|
45
47
|
Klipbook will not overwrite an exiting file by default. You can change this with
|
46
48
|
the `--force` flag.
|
47
49
|
|
48
|
-
You can also specify a maximum count of books you'd like collated with the `--num-books` flag.
|
49
|
-
|
50
50
|
#### From the site
|
51
51
|
|
52
|
-
Specify your
|
52
|
+
Specify your Amazon username and password to klipbook and it will scrape the site and
|
53
53
|
output a clippings file.
|
54
54
|
|
55
55
|
$ klipbook collate site:my-username@blah.com:my-password
|
56
56
|
|
57
57
|
The same flags above apply.
|
58
58
|
|
59
|
-
|
59
|
+
Note that the scraping requires a network connection (obviously) and can take a while
|
60
|
+
so please be patient.
|
61
|
+
|
62
|
+
### Set up defaults
|
63
|
+
|
64
|
+
If you don't feel like having your Amazon credentials in your shell history you can set your
|
60
65
|
default source in the klipbook rc file: `~/.klipbookrc`.
|
61
66
|
|
62
67
|
This is simply a YAML file and you can specify default values for the source and the
|
@@ -78,6 +83,9 @@ The list command lists the books avaiable in the specified source.
|
|
78
83
|
[1] The Big Sleep by Raymond Chandler
|
79
84
|
[2] How to jump out of a plane without a parachute and survive by Rip Rockjaw
|
80
85
|
|
86
|
+
By default it will only list the latest book. This can be overrided with the
|
87
|
+
`--num-books` switch.
|
88
|
+
|
81
89
|
## Installation
|
82
90
|
|
83
91
|
Klipbook is a Ruby gem. To install simply run:
|
data/klipbook.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "klipbook"
|
8
|
-
s.version = "1.0.
|
8
|
+
s.version = "1.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ray Grasso"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-12-12"
|
13
13
|
s.description = "Process your Kindle clippings file to generate a nicely formatted compilation of the clippings of the books you've read"
|
14
14
|
s.email = "ray.grasso@gmail.com"
|
15
15
|
s.executables = ["klipbook"]
|
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
".document",
|
22
22
|
".rspec",
|
23
23
|
".yardopts",
|
24
|
+
"CHANGELOG.txt",
|
24
25
|
"Gemfile",
|
25
26
|
"Gemfile.lock",
|
26
27
|
"Guardfile",
|
@@ -49,7 +50,7 @@ Gem::Specification.new do |s|
|
|
49
50
|
"lib/klipbook/output/html_summary_writer.rb",
|
50
51
|
"lib/klipbook/printer.rb",
|
51
52
|
"lib/klipbook/sources/amazon_site/book_scraper.rb",
|
52
|
-
"lib/klipbook/sources/amazon_site/
|
53
|
+
"lib/klipbook/sources/amazon_site/site_scraper.rb",
|
53
54
|
"lib/klipbook/sources/kindle_device/entry.rb",
|
54
55
|
"lib/klipbook/sources/kindle_device/entry_parser.rb",
|
55
56
|
"lib/klipbook/sources/kindle_device/file.rb",
|
data/lib/klipbook.rb
CHANGED
@@ -7,7 +7,7 @@ require 'klipbook/sources/kindle_device/entry_parser'
|
|
7
7
|
require 'klipbook/sources/kindle_device/entry'
|
8
8
|
require 'klipbook/sources/kindle_device/file'
|
9
9
|
|
10
|
-
require 'klipbook/sources/amazon_site/
|
10
|
+
require 'klipbook/sources/amazon_site/site_scraper'
|
11
11
|
require 'klipbook/sources/amazon_site/book_scraper'
|
12
12
|
|
13
13
|
require 'klipbook/invalid_source_error'
|
data/lib/klipbook/fetcher.rb
CHANGED
@@ -9,7 +9,7 @@ module Klipbook
|
|
9
9
|
elsif (source_spec =~ /site:(.+):(.+)/)
|
10
10
|
username = $1
|
11
11
|
password = $2
|
12
|
-
@source = Klipbook::Sources::AmazonSite::
|
12
|
+
@source = Klipbook::Sources::AmazonSite::SiteScraper.new(username, password, max_books)
|
13
13
|
else
|
14
14
|
raise InvalidSourceError("Unrecognised source type. Only 'file' and 'site' are supported")
|
15
15
|
end
|
@@ -2,7 +2,7 @@ require 'mechanize'
|
|
2
2
|
|
3
3
|
module Klipbook::Sources
|
4
4
|
module AmazonSite
|
5
|
-
class
|
5
|
+
class SiteScraper
|
6
6
|
def initialize(username, password, max_books,
|
7
7
|
book_scraper=Klipbook::Sources::AmazonSite::BookScraper.new,
|
8
8
|
message_stream=$stdout)
|
@@ -10,29 +10,31 @@ module Klipbook::Sources
|
|
10
10
|
@password = password
|
11
11
|
@max_books = max_books
|
12
12
|
@message_stream = message_stream
|
13
|
-
@agent = Mechanize.new
|
13
|
+
@agent = Mechanize.new do |a|
|
14
|
+
a.user_agent_alias = 'Mac Safari'
|
15
|
+
end
|
14
16
|
@book_scraper = book_scraper
|
15
17
|
end
|
16
18
|
|
17
19
|
def books
|
18
|
-
@books ||=
|
20
|
+
@books ||= fetch_up_to_max_books
|
19
21
|
end
|
20
22
|
|
21
23
|
private
|
22
24
|
|
23
|
-
def
|
24
|
-
|
25
|
-
|
26
|
-
signin_submission = @agent.submit(login_form)
|
25
|
+
def fetch_up_to_max_books
|
26
|
+
scrape_books(fetch_first_books_page)
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
+
def fetch_first_books_page
|
30
|
+
welcome_page = get_welcome_page
|
29
31
|
|
30
|
-
|
32
|
+
raise 'Invalid Username or password' unless welcome_page.title == 'Amazon Kindle: Home'
|
31
33
|
|
32
|
-
|
34
|
+
@agent.click(welcome_page.link_with(:text => /Your Highlights/))
|
33
35
|
end
|
34
36
|
|
35
|
-
def
|
37
|
+
def get_welcome_page
|
36
38
|
@message_stream.puts 'Logging into site'
|
37
39
|
|
38
40
|
begin
|
@@ -41,12 +43,12 @@ module Klipbook::Sources
|
|
41
43
|
raise 'Could not connect to Amazon Kindle Site'
|
42
44
|
end
|
43
45
|
|
44
|
-
login_form = page.form('signIn')
|
45
|
-
|
46
|
-
|
47
|
-
|
46
|
+
login_form = page.form('signIn').tap do |f|
|
47
|
+
f.email = @username
|
48
|
+
f.password = @password
|
49
|
+
end
|
48
50
|
|
49
|
-
login_form
|
51
|
+
@agent.submit(login_form)
|
50
52
|
end
|
51
53
|
|
52
54
|
def scrape_books(page)
|
@@ -66,9 +68,9 @@ module Klipbook::Sources
|
|
66
68
|
end
|
67
69
|
|
68
70
|
def get_next_page(page)
|
69
|
-
|
70
|
-
if
|
71
|
-
@agent.
|
71
|
+
next_book_link = page.link_with(:dom_id => "nextBookLink")
|
72
|
+
if next_book_link
|
73
|
+
@agent.click(next_book_link)
|
72
74
|
else
|
73
75
|
nil
|
74
76
|
end
|
data/lib/klipbook/version.rb
CHANGED
@@ -20,12 +20,12 @@ describe Klipbook::Fetcher do
|
|
20
20
|
let(:fetcher) { Klipbook::Fetcher.new('site:username@example.com:password', 2) }
|
21
21
|
|
22
22
|
before(:each) do
|
23
|
-
stub(Klipbook::Sources::AmazonSite::
|
23
|
+
stub(Klipbook::Sources::AmazonSite::SiteScraper).new { fake_source }
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'creates a site scraper with the provided credentials' do
|
27
27
|
subject
|
28
|
-
Klipbook::Sources::AmazonSite::
|
28
|
+
Klipbook::Sources::AmazonSite::SiteScraper.should have_received.new('username@example.com', 'password', 2)
|
29
29
|
end
|
30
30
|
|
31
31
|
describe '#fetch_books' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: klipbook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: gli
|
@@ -264,6 +264,7 @@ files:
|
|
264
264
|
- .document
|
265
265
|
- .rspec
|
266
266
|
- .yardopts
|
267
|
+
- CHANGELOG.txt
|
267
268
|
- Gemfile
|
268
269
|
- Gemfile.lock
|
269
270
|
- Guardfile
|
@@ -292,7 +293,7 @@ files:
|
|
292
293
|
- lib/klipbook/output/html_summary_writer.rb
|
293
294
|
- lib/klipbook/printer.rb
|
294
295
|
- lib/klipbook/sources/amazon_site/book_scraper.rb
|
295
|
-
- lib/klipbook/sources/amazon_site/
|
296
|
+
- lib/klipbook/sources/amazon_site/site_scraper.rb
|
296
297
|
- lib/klipbook/sources/kindle_device/entry.rb
|
297
298
|
- lib/klipbook/sources/kindle_device/entry_parser.rb
|
298
299
|
- lib/klipbook/sources/kindle_device/file.rb
|
@@ -324,7 +325,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
324
325
|
version: '0'
|
325
326
|
segments:
|
326
327
|
- 0
|
327
|
-
hash: -
|
328
|
+
hash: -4595890160696464397
|
328
329
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
329
330
|
none: false
|
330
331
|
requirements:
|