compare_supermarkets 0.3.0 → 0.3.1
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bbf654fdd40a10a41089214f44231f0e8c5cd8656d2aab638cbb6f7de7d2a23
|
4
|
+
data.tar.gz: cacc2dcf4343553a0114ef6b9aa9bad3b298e130913f7dcf5345189504da681d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7b08c8f7f9b5ab53b2d491303db0b52e09bf2bfb3721671c064f4f8a2fda2a262b15695b074a22fe7d18982ad68152f6df7ff1f9949a1ff4d662ecc7587f5d3
|
7
|
+
data.tar.gz: 8a7fe54602b4f222d8b67d0de4928c8101d90834fb1df7ddadf03847e459816dbe93620a78998ed7fbda20975643a0b5896ebd939bed9c95f1181e27bb953964
|
@@ -52,8 +52,8 @@ class CompareSupermarkets::CLI
|
|
52
52
|
change_search_term
|
53
53
|
elsif CompareSupermarkets::Product.count == 0
|
54
54
|
puts ""
|
55
|
-
puts "Ohhh man! Doesn't seem like
|
56
|
-
puts "that product."
|
55
|
+
puts "Ohhh man! Doesn't seem like any of these supermarkets"
|
56
|
+
puts "carry that product."
|
57
57
|
puts ""
|
58
58
|
change_search_term
|
59
59
|
else
|
@@ -7,86 +7,80 @@ class CompareSupermarkets::Scraper
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.search_supermarkets(search_term)
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
supermarkets = ["Coles", "Woolworths", "IGA"]
|
11
|
+
supermarkets.each do |supermarket|
|
12
|
+
search_for(supermarket, search_term)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.search_for(supermarket, search_term)
|
17
|
+
open_browser(supermarket, search_term)
|
13
18
|
end
|
14
19
|
|
15
|
-
def self.
|
20
|
+
def self.open_browser(supermarket, search_term)
|
16
21
|
browser = Watir::Browser.new :chrome
|
17
|
-
|
22
|
+
if supermarket.downcase == "coles"
|
23
|
+
search = "https://shop.coles.com.au/a/national/everything/search/#{search_term}"
|
24
|
+
class_name = "products"
|
25
|
+
elsif supermarket.downcase == "woolworths"
|
26
|
+
search = "https://www.woolworths.com.au/shop/search/products?searchTerm=#{search_term}"
|
27
|
+
class_name = "layoutWrapper"
|
28
|
+
else
|
29
|
+
search = "https://new.igashop.com.au/sm/pickup/rsid/53363/results?q=#{search_term}"
|
30
|
+
class_name = ["Listing-sc-1vfhaq2", "iQljRa"]
|
31
|
+
end
|
32
|
+
browser.goto(search)
|
33
|
+
self.handle_waiting(browser, supermarket, class_name, search_term)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.handle_waiting(browser, supermarket, class_name, search_term)
|
18
37
|
begin
|
19
|
-
|
38
|
+
js_doc = browser.element(class: class_name).wait_until(&:present?)
|
20
39
|
rescue
|
21
|
-
puts "
|
40
|
+
puts "#{supermarket} does not have any #{search_term}"
|
22
41
|
puts ""
|
23
|
-
puts "Let's check Woolworths"
|
24
42
|
puts ""
|
43
|
+
if supermarket.downcase != "iga"
|
44
|
+
puts "Let's check the next one"
|
45
|
+
end
|
25
46
|
puts ""
|
26
47
|
else
|
27
|
-
|
28
|
-
|
29
|
-
coles = CompareSupermarkets::Supermarket.new("Coles")
|
30
|
-
all_coles_products.each do |product|
|
31
|
-
if product.css(".product-name").text != ""
|
32
|
-
coles.add_product(product)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
if coles.products.count == 0
|
36
|
-
puts "Coles do not have this product"
|
37
|
-
end
|
48
|
+
products = Nokogiri::HTML(js_doc.inner_html)
|
49
|
+
self.add_supermarket_products(supermarket, products, search_term)
|
38
50
|
ensure
|
39
51
|
browser.close
|
40
52
|
end
|
41
53
|
end
|
42
54
|
|
43
|
-
def self.
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
rescue
|
49
|
-
puts "Woolworths does not have this product"
|
50
|
-
else
|
51
|
-
woolworths_products = Nokogiri::HTML(woolworths_js_doc.inner_html)
|
52
|
-
woolworths_all_products = woolworths_products.css(".shelfProductTile-content")
|
53
|
-
woolworths = CompareSupermarkets::Supermarket.new("Woolworths")
|
54
|
-
woolworths_all_products.each do |product|
|
55
|
-
if product.css(".shelfProductTile-descriptionLink").text != ""
|
56
|
-
if product.css(".unavailableSection.width-full.ng-star-inserted").empty?
|
57
|
-
woolworths.add_product(product)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
if woolworths.products.count == 0
|
62
|
-
puts "Woolworths do not have this product"
|
55
|
+
def self.add_supermarket_products(supermarket, products, search_term)
|
56
|
+
new_supermarket = CompareSupermarkets::Supermarket.new(supermarket)
|
57
|
+
self.which_supermarket(supermarket, products).each do |product|
|
58
|
+
if check?(supermarket, product, search_term)
|
59
|
+
new_supermarket.add_product(product)
|
63
60
|
end
|
64
|
-
|
65
|
-
|
61
|
+
end
|
62
|
+
if new_supermarket.products.count == 0
|
63
|
+
puts "#{supermarket} do not have any #{search_term}"
|
66
64
|
end
|
67
65
|
end
|
68
66
|
|
69
|
-
def self.
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
rescue
|
75
|
-
puts "iga does not have this product"
|
67
|
+
def self.check?(supermarket, product, search_term)
|
68
|
+
if supermarket.downcase == "coles"
|
69
|
+
check = product.css(".product-name").text != ""
|
70
|
+
elsif supermarket.downcase == "woolworths"
|
71
|
+
check = product.css(".shelfProductTile-descriptionLink").text != ""
|
76
72
|
else
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
ensure
|
89
|
-
browser.close
|
73
|
+
check = product.css(".sc-hKFyIo.bdDYJz").text.downcase[search_term]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.which_supermarket(supermarket, products)
|
78
|
+
if supermarket.downcase == "coles"
|
79
|
+
all_products = products.css(".product")
|
80
|
+
elsif supermarket.downcase == "woolworths"
|
81
|
+
all_products = products.css(".shelfProductTile-content")
|
82
|
+
else
|
83
|
+
all_products = products.css(".ColListing-sc-lcurnl.kYBrWq")
|
90
84
|
end
|
91
85
|
end
|
92
86
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: compare_supermarkets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Berger Howes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-09-
|
11
|
+
date: 2021-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|