amazon_wish_miner 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/amazon_wish_miner/amazon_wish.rb +13 -2
- data/lib/amazon_wish_miner/amazon_wish_list.rb +9 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc34b062b775ba5a0affb2f153989b2782cd1e29eca738841e15e983bfbb2eff
|
4
|
+
data.tar.gz: 14a27724f668364aef570293e1696525d7b21345b199c79d945652f0db875641
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5d3e0a88285addb352a5d680c24231374a0013e8d7b3c12a7d9947f7f147f6c62e2a6d940ff1915b9d7a748e7531607be83cea054f9d98eaaf4a16fa1cd30ba
|
7
|
+
data.tar.gz: fa0ee25c7102b4016bfca9c08beaf4407f866bf0759c014ccf7bd9c8db6ff9a62a6befb752bd1a37d9fe35bc15682b73137a2d0fc771dc7f96a389a9a45db3bf
|
@@ -2,6 +2,10 @@ class AmazonWish
|
|
2
2
|
|
3
3
|
attr_reader :title, :id
|
4
4
|
|
5
|
+
TITLE_TRIMMER = Proc.new do |char|
|
6
|
+
char == "\n" || char == ' '
|
7
|
+
end
|
8
|
+
|
5
9
|
def initialize(id, title)
|
6
10
|
@title = title
|
7
11
|
@id = id
|
@@ -10,7 +14,7 @@ class AmazonWish
|
|
10
14
|
def self.parse_wishes_from_pages(page_responses)
|
11
15
|
list_items = self.list_items_from_response(page_responses)
|
12
16
|
wish_ids = self.draps_from_list_items(list_items)
|
13
|
-
|
17
|
+
wishes_from_ids(wish_ids)
|
14
18
|
end
|
15
19
|
|
16
20
|
def self.list_items_from_response(page_responses)
|
@@ -51,7 +55,9 @@ class AmazonWish
|
|
51
55
|
item_url = 'https://www.amazon.com/dp/' + id
|
52
56
|
response = RestClient.get(item_url)
|
53
57
|
page = Nokogiri::HTML(response)
|
54
|
-
|
58
|
+
title_text = page.css('span[id$="roductTitle"]').children.text
|
59
|
+
title = trim_title(title_text)
|
60
|
+
# not a typo, css selectors are
|
55
61
|
#=> case sensetive, and we need to capture e.g. both "productTitle" and "ebookProductTitle"
|
56
62
|
# price = page.css('priceblock_ourprice')
|
57
63
|
# TODO: parse prices
|
@@ -64,4 +70,9 @@ class AmazonWish
|
|
64
70
|
bullets = feature_bullets_div.css('ul li')
|
65
71
|
end
|
66
72
|
|
73
|
+
def self.trim_title(untrimmed_title)
|
74
|
+
chars = untrimmed_title.chars
|
75
|
+
chars.drop_while(&TITLE_TRIMMER).reverse.drop_while(&TITLE_TRIMMER).reverse.join
|
76
|
+
end
|
77
|
+
|
67
78
|
end
|
@@ -1,11 +1,15 @@
|
|
1
1
|
class AmazonWishList
|
2
2
|
|
3
|
+
attr_accessor :id, :wishes
|
4
|
+
|
3
5
|
REVEAL_OPTIONS = [:all, :purchased, :unpurchased].freeze
|
4
6
|
SORT_OPTIONS = {date_added: "date-added", title: 'universal-title',
|
5
7
|
price_high: 'universal-price-desc', price_low: 'universal-price',
|
6
8
|
date_updated: 'last-updated', priority: 'priority'}.freeze
|
7
9
|
|
8
|
-
def initialize
|
10
|
+
def initialize(id, wishes)
|
11
|
+
@id = id
|
12
|
+
@wishes = wishes
|
9
13
|
end
|
10
14
|
|
11
15
|
# TODO: https://www.amazon.com/hz/wishlist/ls/2WHUDN1UIDVUT/ref=cm_sw_r_cp_ep_ws_8xNVBb731TTMS,
|
@@ -23,6 +27,8 @@ class AmazonWishList
|
|
23
27
|
url_without_qstring = "http://www.amazon.#{tld}/hz/wishlist/ls/#{amazon_list_id}"
|
24
28
|
|
25
29
|
pages = self.get_all_wishlist_pages(url_without_qstring, query_params)
|
30
|
+
wishes = AmazonWish.parse_wishes_from_pages(pages)
|
31
|
+
AmazonWishList.new(amazon_list_id, wishes)
|
26
32
|
end
|
27
33
|
|
28
34
|
def self.get_all_wishlist_pages(url_without_qstring, query_params)
|
@@ -66,8 +72,8 @@ class AmazonWishList
|
|
66
72
|
begin
|
67
73
|
response = RestClient::Request.execute(method: :get, url: url, max_redirects: 0)
|
68
74
|
rescue RestClient::ExceptionWithResponse => err
|
69
|
-
if response.code / 100 == 3
|
70
|
-
url = err.
|
75
|
+
if err.response.code / 100 == 3
|
76
|
+
url = err.response.headers[:location]
|
71
77
|
retry
|
72
78
|
else
|
73
79
|
raise err
|