pricebr_apple 0.7 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +4 -0
- data/lib/pricebr_apple/version.rb +1 -1
- data/lib/pricebr_apple.rb +42 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9a911025711efbca20420c83ef227ffbf83df49
|
4
|
+
data.tar.gz: 8155dd1d7975f2dfd7a1bbb3d35b7b08ade73522
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: baa2fb59f8b5aa5c0d08b8b3c34d63d3677c48c339270cb3419dff6fac6a61157327a39224f737530ce2a0681f7ed89a3f31a470790a175b08dab9230e13e2bb
|
7
|
+
data.tar.gz: 91778b8349aaec62c8dee2231791c122cdbd15ac5ae25c16392a5353af9a5ec20250734731dcfacc47098a8bcad88a66976ffacd91cca78159292d17f27b83ca
|
data/Rakefile
CHANGED
data/lib/pricebr_apple.rb
CHANGED
@@ -22,7 +22,8 @@ module PricebrApple
|
|
22
22
|
"IPAD MINI 4" => "http://www.apple.com/br/shop/buy-ipad/ipad-mini-4",
|
23
23
|
"IPAD MINI 2" => "http://www.apple.com/br/shop/buy-ipad/ipad-mini-2",
|
24
24
|
"WATCH SERIES 1" => "http://www.apple.com/br/shop/buy-watch/apple-watch-series-1",
|
25
|
-
"WATCH" => "http://www.apple.com/br/shop/buy-watch/apple-watch",
|
25
|
+
"WATCH SERIE 2" => "http://www.apple.com/br/shop/buy-watch/apple-watch",
|
26
|
+
"WATCH SERIE 2 EDITION" =>"http://www.apple.com/br/shop/buy-watch/apple-watch/branco-cer%C3%A2mica-nuvem-pulseira-esportiva?product=MNPF2BZ/A&step=detail",
|
26
27
|
}
|
27
28
|
|
28
29
|
class PriceBR
|
@@ -44,13 +45,12 @@ module PricebrApple
|
|
44
45
|
def get_price(params)
|
45
46
|
@model = params[:partNumber]
|
46
47
|
url_page = params[:url_page]
|
47
|
-
if
|
48
|
+
if !url_page.nil? && !@model.nil?
|
48
49
|
@page = Nokogiri::HTML(open(url_page))
|
49
50
|
list_price = @page.css('.current_price')
|
50
51
|
list_price = @page.css('.as-price-currentprice') if list_price.empty?
|
51
52
|
unless list_price.nil?
|
52
53
|
list_price.map{|item| @price = item.children[1].children[3].children[0].text.gsub(' ', '').gsub("\nR$",'').gsub("\n",'').gsub('.','').gsub(',','.').to_f if !item.nil? && item.children[1].children[1].values[1].to_s == @model}
|
53
|
-
@price = self.script_crawler({script: list_price, partNumber: @model}) if @price.nil?
|
54
54
|
else
|
55
55
|
@price = 0.0
|
56
56
|
end
|
@@ -64,8 +64,32 @@ module PricebrApple
|
|
64
64
|
|
65
65
|
# params {script: 'text', partNumber: 'model'}
|
66
66
|
def script_crawler(params)
|
67
|
-
|
67
|
+
list = []
|
68
|
+
download = open(params[:url_page]) unless params[:url_page].nil?
|
69
|
+
unless download.nil?
|
70
|
+
download.each do |line|
|
71
|
+
if !line.nil? && (line.include? 'partNumber') && (line.include? 'currentPrice')
|
72
|
+
frame = line.split('"products"')
|
73
|
+
frame = frame.last.split('"dimensionCapacity"')
|
74
|
+
frame.each do |item|
|
75
|
+
if !item.nil? && (item.include? 'partNumber') && (item.include? 'price')
|
76
|
+
part = item.split('partNumber')
|
77
|
+
if part.size == 2
|
78
|
+
partNumber, part = part[1].split('seoUrlToken')
|
79
|
+
unless part.nil?
|
80
|
+
part = part.split('carrierPolicyPart').first
|
81
|
+
price = part.split('price').last
|
82
|
+
price = self.cleaning(price)
|
83
|
+
end
|
84
|
+
partNumber = self.cleaning(partNumber)
|
85
|
+
list << [ partNumber, price.to_f ] if !partNumber.nil? && !price.nil?
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
68
91
|
end
|
92
|
+
return list.empty? ? nil : list
|
69
93
|
end
|
70
94
|
|
71
95
|
# params {url_page : 'http://'}
|
@@ -80,13 +104,23 @@ module PricebrApple
|
|
80
104
|
def update_price
|
81
105
|
list = []
|
82
106
|
PRICE_URL.each do |x,y|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
list
|
107
|
+
new_format = ["IPHONE 7 PLUS", "IPHONE 7", "IPHONE 6S", "IPHONE 6S PLUS", "IPHONE SE", "WATCH SERIES 1", "WATCH SERIE 2", "WATCH SERIE 2 EDITION"]
|
108
|
+
if (new_format.include? x)
|
109
|
+
sub_list = script_crawler({url_page: y})
|
110
|
+
list = list + sub_list unless sub_list.nil?
|
111
|
+
else
|
112
|
+
get_list_partNumber({url_page: y})
|
113
|
+
@list_partNumber.each do |part|
|
114
|
+
self.get_price({url_page: y, partNumber: part})
|
115
|
+
list << [ part, self.get_last_price ]
|
116
|
+
end
|
87
117
|
end
|
88
118
|
end
|
89
119
|
return list
|
90
120
|
end
|
121
|
+
|
122
|
+
def cleaning(str = nil)
|
123
|
+
str.to_s.gsub('"','').gsub(':','').gsub(',','').gsub('_','.') unless str.nil?
|
124
|
+
end
|
91
125
|
end
|
92
126
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pricebr_apple
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eduardo Alencar
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|