siuying-kindle-highlights 0.0.6 → 0.0.7

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 +12 -8
  2. metadata +5 -5
@@ -17,7 +17,7 @@ class KindleHighlight
17
17
  @amazon_form.password = password
18
18
  end
19
19
 
20
- def scrape_highlights
20
+ def scrape_highlights(should_lookup_book=true)
21
21
  if self.next_url.nil?
22
22
  signin_submission = @agent.submit(@amazon_form)
23
23
  highlights_page = @agent.click(signin_submission.link_with(:text => /Your Highlights/))
@@ -27,8 +27,8 @@ class KindleHighlight
27
27
  end
28
28
 
29
29
  new_highlights = Array.new
30
- highlights_page.search(".//div[@class='highlightRow yourHighlight']").each do |h|
31
- new_highlights << Highlight.new(h)
30
+ highlights_page.search(".//div[@class='highlightRow yourHighlight']").each do |highlight|
31
+ new_highlights << Highlight.new(highlight, should_lookup_book)
32
32
  end
33
33
  self.highlights = self.highlights + new_highlights
34
34
  self.next_url = highlights_page.search("a#nextBookLink").attribute('href') rescue nil
@@ -48,13 +48,16 @@ class KindleHighlight::Highlight
48
48
 
49
49
  @@amazon_items = Hash.new
50
50
 
51
- def initialize(highlight)
51
+ def initialize(highlight, should_lookup_book=true)
52
52
  self.annotation_id = highlight.xpath("form/input[@id='annotation_id']").attribute("value").value
53
53
  self.asin = highlight.xpath("p/span[@class='hidden asin']").text
54
54
  self.content = highlight.xpath("span[@class='highlight']").text rescue ""
55
55
  self.note = highlight.xpath("span[@class='noteContent']").text rescue ""
56
56
  self.end_location = highlight.xpath("span[@class='end_location']").text
57
+ lookup_item if should_lookup_book
58
+ end
57
59
 
60
+ def lookup_item
58
61
  amazon_item = lookup_or_get_from_cache(self.asin)
59
62
  self.title = amazon_item.title
60
63
  self.author = amazon_item.raw.ItemAttributes.Author rescue nil
@@ -62,14 +65,15 @@ class KindleHighlight::Highlight
62
65
  self.image_url = amazon_item.image_url
63
66
  end
64
67
 
68
+ def to_s
69
+ "<Highlight##{annotation_id}>"
70
+ end
71
+
72
+ private
65
73
  def lookup_or_get_from_cache(asin)
66
74
  unless @@amazon_items.has_key?(asin)
67
75
  @@amazon_items[asin] = lookup(asin).first
68
76
  end
69
77
  @@amazon_items[asin]
70
78
  end
71
-
72
- def to_s
73
- "<Highlight##{annotation_id}>"
74
- end
75
79
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: siuying-kindle-highlights
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ date: 2012-10-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: mechanize
17
- requirement: &70358233487240 !ruby/object:Gem::Requirement
17
+ requirement: &70186434739480 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 2.0.1
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70358233487240
25
+ version_requirements: *70186434739480
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: asin
28
- requirement: &70358233437920 !ruby/object:Gem::Requirement
28
+ requirement: &70186434738360 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: 1.0.0
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70358233437920
36
+ version_requirements: *70186434738360
37
37
  description: Until there is a Kindle API, this will suffice.
38
38
  email:
39
39
  - eric@prudentiadigital.com