compare_supermarkets 0.3.1 → 0.4.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 +4 -4
- data/bin/console +0 -3
- data/bin/setup +1 -2
- data/config/environment.rb +0 -3
- data/lib/compare_supermarkets/cli.rb +6 -9
- data/lib/compare_supermarkets/scraper.rb +34 -57
- data/lib/compare_supermarkets/supermarket.rb +36 -33
- data/lib/compare_supermarkets/version.rb +1 -1
- metadata +14 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1791e9c3f62f3acd466b46d1c3a1cbce45f05788a1749e7f8c287d0ebf053abb
|
4
|
+
data.tar.gz: bf7badf710b0be6ad961db733eba0800933935245e8b8de93f45d6a8958f016b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd5dc190434e70a8c8df56d6b0d20908db2f55f977d7afe3509ea7b13799b3b4bda6012da2dcaff30cdf34ac4a3e78b1f48c2b1778b8b8d10edbb3a58fdb1b54
|
7
|
+
data.tar.gz: ec6273911b70374dca339d606a2588e71bd80c876561d4dece1f2065296f67ea0776056a82c84d95eb17a4e32e03e7bb5740e3fae2c6ef6e26e53b7ea5540885
|
data/bin/console
CHANGED
data/bin/setup
CHANGED
data/config/environment.rb
CHANGED
@@ -2,9 +2,6 @@ require 'pry'
|
|
2
2
|
require 'nokogiri'
|
3
3
|
require 'watir'
|
4
4
|
|
5
|
-
#gem install selenium-webdriver - required for watir to work
|
6
|
-
#brew install --cask chromedriver - required for watir to work
|
7
|
-
|
8
5
|
require_relative '../lib/compare_supermarkets/scraper'
|
9
6
|
require_relative '../lib/compare_supermarkets/product'
|
10
7
|
require_relative '../lib/compare_supermarkets/cli'
|
@@ -5,7 +5,7 @@ class CompareSupermarkets::CLI
|
|
5
5
|
puts ""
|
6
6
|
puts "Type q at any time to exit."
|
7
7
|
puts ""
|
8
|
-
puts "Would you like to compare prices between Coles
|
8
|
+
puts "Would you like to compare prices between Coles and Woolworths (Y/N)"
|
9
9
|
input = gets.strip.downcase
|
10
10
|
puts ""
|
11
11
|
if input == "y"
|
@@ -49,6 +49,8 @@ class CompareSupermarkets::CLI
|
|
49
49
|
puts "If you were a little more specific with your search"
|
50
50
|
puts "term, we would have less to sort through..."
|
51
51
|
puts ""
|
52
|
+
puts "If you still want to see all of these results, select N"
|
53
|
+
puts ""
|
52
54
|
change_search_term
|
53
55
|
elsif CompareSupermarkets::Product.count == 0
|
54
56
|
puts ""
|
@@ -58,7 +60,7 @@ class CompareSupermarkets::CLI
|
|
58
60
|
change_search_term
|
59
61
|
else
|
60
62
|
puts ""
|
61
|
-
puts "Great! We have #{CompareSupermarkets::Product.count} items for you."
|
63
|
+
puts "Great! We have #{CompareSupermarkets::Product.count} items in stock for you."
|
62
64
|
puts ""
|
63
65
|
puts ""
|
64
66
|
puts ""
|
@@ -67,7 +69,8 @@ class CompareSupermarkets::CLI
|
|
67
69
|
end
|
68
70
|
|
69
71
|
def search_supermarkets(input)
|
70
|
-
|
72
|
+
supermarkets = ["Coles", "Woolworths"]
|
73
|
+
CompareSupermarkets::Scraper.search_supermarkets(supermarkets, input)
|
71
74
|
end
|
72
75
|
|
73
76
|
def change_search_term
|
@@ -111,8 +114,6 @@ class CompareSupermarkets::CLI
|
|
111
114
|
puts ""
|
112
115
|
puts "5 - Only Woolworths items"
|
113
116
|
puts ""
|
114
|
-
puts "6 - Only IGA items"
|
115
|
-
puts ""
|
116
117
|
input = gets.strip
|
117
118
|
puts ""
|
118
119
|
choice(input)
|
@@ -137,10 +138,6 @@ class CompareSupermarkets::CLI
|
|
137
138
|
how_to_sort ? direction = "asc" : direction = "desc"
|
138
139
|
choice = CompareSupermarkets::Product.woolworths_sorted_by_price
|
139
140
|
print_items(choice, direction)
|
140
|
-
elsif input == "6"
|
141
|
-
how_to_sort ? direction = "asc" : direction = "desc"
|
142
|
-
choice = CompareSupermarkets::Product.iga_sorted_by_price
|
143
|
-
print_items(choice, direction)
|
144
141
|
elsif input == ""
|
145
142
|
invalid_input
|
146
143
|
how_to_display
|
@@ -6,81 +6,58 @@ class CompareSupermarkets::Scraper
|
|
6
6
|
@search_term = search_term
|
7
7
|
end
|
8
8
|
|
9
|
-
def self.search_supermarkets(search_term)
|
10
|
-
supermarkets = ["Coles", "Woolworths", "IGA"]
|
9
|
+
def self.search_supermarkets(supermarkets, search_term)
|
11
10
|
supermarkets.each do |supermarket|
|
12
|
-
|
11
|
+
Kernel.const_get("CompareSupermarkets::#{supermarket}Scraper").search_browser(search_term)
|
13
12
|
end
|
14
13
|
end
|
15
14
|
|
16
|
-
def self.
|
17
|
-
open_browser(supermarket, search_term)
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.open_browser(supermarket, search_term)
|
15
|
+
def self.handle_waiting(supermarket, class_name, all_products, search, check)
|
21
16
|
browser = Watir::Browser.new :chrome
|
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)
|
37
17
|
begin
|
18
|
+
browser.goto(search)
|
38
19
|
js_doc = browser.element(class: class_name).wait_until(&:present?)
|
39
20
|
rescue
|
40
|
-
puts "
|
41
|
-
puts ""
|
42
|
-
puts ""
|
43
|
-
if supermarket.downcase != "iga"
|
44
|
-
puts "Let's check the next one"
|
45
|
-
end
|
21
|
+
puts "This product cannot be found"
|
46
22
|
puts ""
|
47
23
|
else
|
24
|
+
new_supermarket = Kernel.const_get("CompareSupermarkets::#{supermarket}").new(supermarket)
|
48
25
|
products = Nokogiri::HTML(js_doc.inner_html)
|
49
|
-
|
26
|
+
products.css(all_products).each do |product|
|
27
|
+
if product.css(check).text != ""
|
28
|
+
new_supermarket.add_product(product)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
if new_supermarket.products.count == 0
|
32
|
+
puts "#{supermarket} do not have this item"
|
33
|
+
end
|
50
34
|
ensure
|
51
35
|
browser.close
|
52
36
|
end
|
53
37
|
end
|
38
|
+
end
|
54
39
|
|
55
|
-
|
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)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
if new_supermarket.products.count == 0
|
63
|
-
puts "#{supermarket} do not have any #{search_term}"
|
64
|
-
end
|
65
|
-
end
|
40
|
+
class CompareSupermarkets::ColesScraper < CompareSupermarkets::Scraper
|
66
41
|
|
67
|
-
def self.
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
check = product.css(".sc-hKFyIo.bdDYJz").text.downcase[search_term]
|
74
|
-
end
|
42
|
+
def self.search_browser(search_term)
|
43
|
+
search = "https://shop.coles.com.au/a/national/everything/search/#{search_term}"
|
44
|
+
class_name = "products"
|
45
|
+
all_products = ".product"
|
46
|
+
check = ".product-name"
|
47
|
+
self.handle_waiting('Coles', class_name, all_products, search, check)
|
75
48
|
end
|
76
49
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
50
|
+
end
|
51
|
+
|
52
|
+
class CompareSupermarkets::WoolworthsScraper < CompareSupermarkets::Scraper
|
53
|
+
|
54
|
+
def self.search_browser(search_term)
|
55
|
+
search = "https://www.woolworths.com.au/shop/search/products?searchTerm=#{search_term}"
|
56
|
+
all_products = ".shelfProductTile-content"
|
57
|
+
class_name = "layoutWrapper"
|
58
|
+
check = ".shelfProductTile-descriptionLink"
|
59
|
+
self.handle_waiting('Woolworths', class_name, all_products, search, check)
|
85
60
|
end
|
61
|
+
|
86
62
|
end
|
63
|
+
|
@@ -13,39 +13,8 @@ class CompareSupermarkets::Supermarket
|
|
13
13
|
@@all
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
|
18
|
-
new_product = CompareSupermarkets::Product.new(self,
|
19
|
-
product.css(".product-name").text,
|
20
|
-
product.css(".package-price").text.delete_prefix('$').gsub('per', '/'),
|
21
|
-
product.css(".package-size.accessibility-inline").text.chomp(' '),
|
22
|
-
product.css(".product-image-link").attribute('href'),
|
23
|
-
product.css(".dollar-value").text,
|
24
|
-
product.css(".cent-value").text.delete_prefix('.'))
|
25
|
-
elsif self.name == "Woolworths"
|
26
|
-
new_product = CompareSupermarkets::Product.new(self,
|
27
|
-
product.css(".shelfProductTile-descriptionLink").text,
|
28
|
-
product.css(".shelfProductTile-cupPrice.ng-star-inserted").text.delete_prefix(' $').chomp(" "),
|
29
|
-
product.css(".shelfProductTile-descriptionLink").text.split(" ").last,
|
30
|
-
product.css(".shelfProductTile-descriptionLink").attribute('href').value,
|
31
|
-
product.css(".price-dollars").text,
|
32
|
-
product.css(".price-cents").text)
|
33
|
-
else
|
34
|
-
price_css = if product.css(".ProductCardPrice-sc-zgh1l1.hwVjs").text.delete_prefix("$").split(".").first
|
35
|
-
".ProductCardPrice-sc-zgh1l1.hwVjs"
|
36
|
-
else
|
37
|
-
".ProductCardPrice-sc-zgh1l1.jYaBFk"
|
38
|
-
end
|
39
|
-
new_product = CompareSupermarkets::Product.new(self,
|
40
|
-
product.css(".sc-hKFyIo.bdDYJz").text.split(', ').first,
|
41
|
-
product.css(".ProductCardPriceInfo-sc-1o21dmb.iDDqhD").text.delete_prefix("$").gsub("/", " / "),
|
42
|
-
product.css(".sc-hKFyIo.bdDYJz").text.split(', ').last,
|
43
|
-
product.css(".ProductCardHiddenLink-sc-y1ynto.hGUSDV").attribute('href').value,
|
44
|
-
product.css(price_css).text.delete_prefix("$").split(".").first,
|
45
|
-
product.css(price_css).text.split(".").last.chomp(" avg/ea")
|
46
|
-
)
|
47
|
-
end
|
48
|
-
@products << new_product
|
16
|
+
def self.out_of_stock
|
17
|
+
@out_of_stock.count
|
49
18
|
end
|
50
19
|
|
51
20
|
def products
|
@@ -56,4 +25,38 @@ class CompareSupermarkets::Supermarket
|
|
56
25
|
@@all.clear
|
57
26
|
end
|
58
27
|
|
28
|
+
end
|
29
|
+
|
30
|
+
class CompareSupermarkets::Coles < CompareSupermarkets::Supermarket
|
31
|
+
|
32
|
+
def add_product(product)
|
33
|
+
supermarket = self
|
34
|
+
name = product.css(".product-name").text
|
35
|
+
price = product.css(".package-price").text.delete_prefix('$').gsub('per', '/')
|
36
|
+
unit_size = product.css(".package-size.accessibility-inline").text.chomp(' ')
|
37
|
+
url = product.css(".product-image-link").attribute('href')
|
38
|
+
dollar_value = product.css(".dollar-value").text
|
39
|
+
cent_value = product.css(".cent-value").text.delete_prefix('.')
|
40
|
+
if dollar_value != "0" && cent_value != "0"
|
41
|
+
new_product = CompareSupermarkets::Product.new(supermarket, name, price, unit_size, url, dollar_value, cent_value)
|
42
|
+
@products << new_product
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class CompareSupermarkets::Woolworths < CompareSupermarkets::Supermarket
|
48
|
+
|
49
|
+
def add_product(product)
|
50
|
+
supermarket = self
|
51
|
+
name = product.css(".shelfProductTile-descriptionLink").text
|
52
|
+
price = product.css(".shelfProductTile-cupPrice.ng-star-inserted").text.delete_prefix(' $').chomp(" ")
|
53
|
+
unit_size = product.css(".shelfProductTile-descriptionLink").text.split(" ").last
|
54
|
+
url = product.css(".shelfProductTile-descriptionLink").attribute('href').value
|
55
|
+
dollar_value = product.css(".price-dollars").text
|
56
|
+
cent_value = product.css(".price-cents").text
|
57
|
+
if dollar_value != "0" && cent_value != "0"
|
58
|
+
new_product = CompareSupermarkets::Product.new(supermarket, name, price, unit_size, url, dollar_value, cent_value)
|
59
|
+
@products << new_product
|
60
|
+
end
|
61
|
+
end
|
59
62
|
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.
|
4
|
+
version: 0.4.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-
|
11
|
+
date: 2021-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -53,33 +53,33 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 3.10.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: pry
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
62
|
-
type: :
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: nokogiri
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
76
|
-
type: :
|
75
|
+
version: 1.10.8
|
76
|
+
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 1.10.8
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: watir
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: 6.19.1
|
90
|
-
type: :
|
90
|
+
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
@@ -101,15 +101,15 @@ dependencies:
|
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: 3.142.7
|
104
|
-
type: :
|
104
|
+
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: 3.142.7
|
111
|
-
description: Will search Woolworths
|
112
|
-
|
111
|
+
description: Will search Woolworths and Coles online stores for prices based on an
|
112
|
+
input search parameter **Google Chrome Required**
|
113
113
|
email:
|
114
114
|
- happymelonbox@gmail.com
|
115
115
|
executables:
|