kindle-highlights 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/kindle_highlights.rb +9 -0
- data/lib/kindle_highlights/highlight.rb +27 -0
- data/lib/kindle_highlights/kindle_highlight.rb +25 -0
- metadata +20 -8
- data/lib/kindle-highlights.rb +0 -58
@@ -0,0 +1,27 @@
|
|
1
|
+
class KindleHighlight::Highlight
|
2
|
+
|
3
|
+
attr_accessor :annotation_id, :asin, :author, :title, :content
|
4
|
+
|
5
|
+
@@amazon_items = Hash.new
|
6
|
+
|
7
|
+
def initialize(highlight)
|
8
|
+
self.annotation_id = highlight.xpath("form/input[@id='annotation_id']").attribute("value").value
|
9
|
+
self.asin = highlight.xpath("p/span[@class='hidden asin']").text
|
10
|
+
self.content = highlight.xpath("span[@class='highlight']").text
|
11
|
+
amazon_item = lookup_or_get_from_cache(self.asin)
|
12
|
+
self.author = amazon_item.item_attributes.author.to_s
|
13
|
+
self.title = amazon_item.item_attributes.title.to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
def lookup_or_get_from_cache(asin)
|
17
|
+
unless @@amazon_items.has_key?(asin)
|
18
|
+
request = Request.new
|
19
|
+
request.locale = 'us'
|
20
|
+
response = ResponseGroup.new('Small')
|
21
|
+
lookup = Amazon::AWS::ItemLookup.new('ASIN', {'ItemId' => asin, 'MerchantId' => 'Amazon'})
|
22
|
+
amazon_item = request.search(lookup, response).item_lookup_response[0].items.item.first
|
23
|
+
@@amazon_items[asin] = amazon_item
|
24
|
+
end
|
25
|
+
@@amazon_items[asin]
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class KindleHighlight
|
2
|
+
|
3
|
+
attr_accessor :highlights
|
4
|
+
|
5
|
+
def initialize(email_address, password)
|
6
|
+
@agent = Mechanize.new
|
7
|
+
@agent.user_agent_alias = 'Mac Safari'
|
8
|
+
page = @agent.get("https://www.amazon.com/ap/signin?openid.assoc_handle=amzn_kindle&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.pape.max_auth_age=0&openid.mode=checkid_setup&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.return_to=https%3A%2F%2Fkindle.amazon.com%3A443%2Fauthenticate%2Flogin_callback%3Fwctx%3D%252F&pageId=amzn_kindle")
|
9
|
+
@amazon_form = page.form('signIn')
|
10
|
+
@amazon_form.email = email_address
|
11
|
+
@amazon_form.password = password
|
12
|
+
scrape_highlights
|
13
|
+
end
|
14
|
+
|
15
|
+
def scrape_highlights
|
16
|
+
signin_submission = @agent.submit(@amazon_form)
|
17
|
+
highlights_page = @agent.click(signin_submission.link_with(:text => /Your Highlights/))
|
18
|
+
collected_highlights = Array.new
|
19
|
+
highlights_page.search(".//div[@class='highlightRow yourHighlight']").each do |h|
|
20
|
+
collected_highlights << Highlight.new(h)
|
21
|
+
end
|
22
|
+
self.highlights = collected_highlights
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kindle-highlights
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-11-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mechanize
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: 2.0.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.0.1
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: ruby-aaws
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,14 +37,21 @@ dependencies:
|
|
32
37
|
version: 0.7.0
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.7.0
|
36
46
|
description: Until there is a Kindle API, this will suffice.
|
37
47
|
email: eric@prudentiadigital.com
|
38
48
|
executables: []
|
39
49
|
extensions: []
|
40
50
|
extra_rdoc_files: []
|
41
51
|
files:
|
42
|
-
- lib/
|
52
|
+
- lib/kindle_highlights.rb
|
53
|
+
- lib/kindle_highlights/kindle_highlight.rb
|
54
|
+
- lib/kindle_highlights/highlight.rb
|
43
55
|
homepage: https://github.com/speric/kindle-highlights
|
44
56
|
licenses: []
|
45
57
|
post_install_message:
|
@@ -60,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
72
|
version: '0'
|
61
73
|
requirements: []
|
62
74
|
rubyforge_project:
|
63
|
-
rubygems_version: 1.8.
|
75
|
+
rubygems_version: 1.8.22
|
64
76
|
signing_key:
|
65
77
|
specification_version: 3
|
66
78
|
summary: Kindle highlights
|
data/lib/kindle-highlights.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'mechanize'
|
3
|
-
require 'amazon/aws'
|
4
|
-
require 'amazon/aws/search'
|
5
|
-
|
6
|
-
include Amazon::AWS
|
7
|
-
include Amazon::AWS::Search
|
8
|
-
|
9
|
-
class KindleHighlight
|
10
|
-
attr_accessor :highlights
|
11
|
-
|
12
|
-
def initialize(email_address, password)
|
13
|
-
@agent = Mechanize.new
|
14
|
-
page = @agent.get("https://www.amazon.com/ap/signin?openid.return_to=https%3A%2F%2Fkindle.amazon.com%3A443%2Fauthenticate%2Flogin_callback%3Fwctx%3D%252F&pageId=amzn_kindle&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.pape.max_auth_age=0&openid.assoc_handle=amzn_kindle&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select")
|
15
|
-
@amazon_form = page.form('signIn')
|
16
|
-
@amazon_form.email = email_address
|
17
|
-
@amazon_form.password = password
|
18
|
-
scrape_highlights
|
19
|
-
end
|
20
|
-
|
21
|
-
def scrape_highlights
|
22
|
-
signin_submission = @agent.submit(@amazon_form)
|
23
|
-
highlights_page = @agent.click(signin_submission.link_with(:text => /Your Highlights/))
|
24
|
-
collected_highlights = Array.new
|
25
|
-
highlights_page.search(".//div[@class='highlightRow yourHighlight']").each do |h|
|
26
|
-
collected_highlights << Highlight.new(h)
|
27
|
-
end
|
28
|
-
self.highlights = collected_highlights
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
class KindleHighlight::Highlight
|
33
|
-
|
34
|
-
attr_accessor :annotation_id, :asin, :author, :title, :content
|
35
|
-
|
36
|
-
@@amazon_items = Hash.new
|
37
|
-
|
38
|
-
def initialize(highlight)
|
39
|
-
self.annotation_id = highlight.xpath("form/input[@id='annotation_id']").attribute("value").value
|
40
|
-
self.asin = highlight.xpath("p/span[@class='hidden asin']").text
|
41
|
-
self.content = highlight.xpath("span[@class='highlight']").text
|
42
|
-
amazon_item = lookup_or_get_from_cache(self.asin)
|
43
|
-
self.author = amazon_item.item_attributes.author.to_s
|
44
|
-
self.title = amazon_item.item_attributes.title.to_s
|
45
|
-
end
|
46
|
-
|
47
|
-
def lookup_or_get_from_cache(asin)
|
48
|
-
unless @@amazon_items.has_key?(asin)
|
49
|
-
request = Request.new
|
50
|
-
request.locale = 'us'
|
51
|
-
response = ResponseGroup.new('Small')
|
52
|
-
lookup = Amazon::AWS::ItemLookup.new('ASIN', {'ItemId' => asin, 'MerchantId' => 'Amazon'})
|
53
|
-
amazon_item = request.search(lookup, response).item_lookup_response[0].items.item.first
|
54
|
-
@@amazon_items[asin] = amazon_item
|
55
|
-
end
|
56
|
-
@@amazon_items[asin]
|
57
|
-
end
|
58
|
-
end
|