kindle-highlights 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/kindle-highlights.rb +48 -0
  2. metadata +67 -0
@@ -0,0 +1,48 @@
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
+ def initialize(highlight)
37
+ self.annotation_id = highlight.xpath("form/input[@id='annotation_id']").attribute("value").value
38
+ self.asin = highlight.xpath("p/span[@class='hidden asin']").text
39
+ self.content = highlight.xpath("span[@class='highlight']").text
40
+ @request = Request.new
41
+ @request.locale = 'us'
42
+ @response = ResponseGroup.new('Medium')
43
+ lookup = Amazon::AWS::ItemLookup.new('ASIN', {'ItemId' => self.asin, 'MerchantId' => 'Amazon'})
44
+ item = @request.search(lookup, @response).item_lookup_response[0].items.item.first
45
+ self.author = item.item_attributes.author.first.to_s
46
+ self.title = item.item_attributes.title.first.to_s
47
+ end
48
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kindle-highlights
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Eric Farkas
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-20 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mechanize
16
+ requirement: &9429540 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.0.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *9429540
25
+ - !ruby/object:Gem::Dependency
26
+ name: ruby-aaws
27
+ requirement: &9429240 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 0.7.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *9429240
36
+ description: Until there is a Kindle API, this will suffice.
37
+ email: eric@prudentiadigital.com
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files: []
41
+ files:
42
+ - lib/kindle-highlights.rb
43
+ homepage: https://github.com/speric/kindle-highlights
44
+ licenses: []
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 1.7.2
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Kindle highlights
67
+ test_files: []