compare_supermarkets 0.4.1 → 0.4.2
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: 9d8890834ce5a37d23206a1a513f3c57ec0caea90593373662baefdfc2062794
|
4
|
+
data.tar.gz: a6ed1f030433fed9f6cbde6629f384f3e312fb3e3f0edcfa4d193aa4585c4416
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 483653e82b680078090c4b8234086fa8b0bf8a89a8e635902b3b3482f70117f7f1342367a89299c994a3f4029648896191f2a99df417a241a16f9a278d60e47c
|
7
|
+
data.tar.gz: df5dd2e030710133081f2c5d0e4a413daee5e05958bde06d05c90440d4fa23ddc35e953efbaaecaa72fdc55e19f47d4815550de6ee19581bc77cdc5f92d3e501
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class CompareSupermarkets::CLI
|
2
2
|
def call
|
3
3
|
puts ""
|
4
|
-
puts "Welcome to
|
4
|
+
puts "Welcome to Compare_Supermarkets"
|
5
5
|
puts ""
|
6
6
|
puts "Type q at any time to exit."
|
7
7
|
puts ""
|
@@ -29,7 +29,7 @@ class CompareSupermarkets::CLI
|
|
29
29
|
def start
|
30
30
|
puts ""
|
31
31
|
puts "Great!"
|
32
|
-
puts "Please enter the name of the item you wish to compare"
|
32
|
+
puts "Please enter the name of the item you wish to compare (example: red tractor oats or purple sweet potato)"
|
33
33
|
input = gets.strip.downcase
|
34
34
|
puts ""
|
35
35
|
puts ""
|
@@ -151,7 +151,7 @@ class CompareSupermarkets::CLI
|
|
151
151
|
|
152
152
|
def finished
|
153
153
|
puts ""
|
154
|
-
puts "Is this what you were looking for?(Y/N)"
|
154
|
+
puts "Is this what you were looking for? (Y/N)"
|
155
155
|
input = gets.strip.downcase
|
156
156
|
if input == "y"
|
157
157
|
puts ""
|
@@ -240,6 +240,7 @@ class CompareSupermarkets::CLI
|
|
240
240
|
def how_to_sort
|
241
241
|
puts ""
|
242
242
|
puts "How would you like your results sorted?"
|
243
|
+
puts ""
|
243
244
|
puts "1 - Cheapest to most expensive"
|
244
245
|
puts "2 - Most expensive to cheapest"
|
245
246
|
puts ""
|
@@ -10,13 +10,7 @@ class CompareSupermarkets::Product
|
|
10
10
|
@unit_size = unit_size
|
11
11
|
@dollar_value = dollar_value
|
12
12
|
@cent_value = cent_value
|
13
|
-
@url =
|
14
|
-
"https://shop.coles.com.au#{url}"
|
15
|
-
elsif @supermarket.name == "Woolworths"
|
16
|
-
"https://www.woolworths.com.au#{url}"
|
17
|
-
else
|
18
|
-
url
|
19
|
-
end
|
13
|
+
@url = url
|
20
14
|
@@all << self
|
21
15
|
end
|
22
16
|
|
@@ -8,55 +8,62 @@ class CompareSupermarkets::Scraper
|
|
8
8
|
|
9
9
|
def self.search_supermarkets(supermarkets, search_term)
|
10
10
|
supermarkets.each do |supermarket|
|
11
|
-
|
11
|
+
new_supermarket = Kernel.const_get("CompareSupermarkets::#{supermarket}Scraper").new(search_term)
|
12
|
+
new_supermarket.search_browser
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
15
|
-
def
|
16
|
+
def handle_waiting(supermarket, class_name, all_products, search, search_term, check)
|
16
17
|
browser = Watir::Browser.new :chrome
|
17
18
|
begin
|
18
|
-
browser.goto(search)
|
19
|
+
browser.goto(search+search_term)
|
19
20
|
js_doc = browser.element(class: class_name).wait_until(&:present?)
|
20
21
|
rescue
|
21
22
|
puts "This product cannot be found"
|
22
23
|
puts ""
|
23
24
|
else
|
24
|
-
new_supermarket = Kernel.const_get("CompareSupermarkets::#{supermarket}").new(supermarket)
|
25
25
|
products = Nokogiri::HTML(js_doc.inner_html)
|
26
26
|
products.css(all_products).each do |product|
|
27
27
|
if product.css(check).text != ""
|
28
|
-
new_supermarket.
|
28
|
+
new_supermarket = Kernel.const_get("CompareSupermarkets::#{supermarket}").new(product)
|
29
|
+
new_supermarket.add_product
|
29
30
|
end
|
30
31
|
end
|
31
|
-
if
|
32
|
+
if Kernel.const_get("CompareSupermarkets::#{supermarket}").all_products.count == 0
|
32
33
|
puts "#{supermarket} do not have this item"
|
33
34
|
end
|
34
35
|
ensure
|
35
36
|
browser.close
|
36
37
|
end
|
37
38
|
end
|
39
|
+
|
40
|
+
def search_browser
|
41
|
+
handle_waiting(@supermarket, @class_name, @all_products, @search, @search_term, @check)
|
42
|
+
end
|
38
43
|
end
|
39
44
|
|
40
45
|
class CompareSupermarkets::ColesScraper < CompareSupermarkets::Scraper
|
41
46
|
|
42
|
-
def
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
47
|
+
def initialize(search_term)
|
48
|
+
@supermarket = 'Coles'
|
49
|
+
@search = "https://shop.coles.com.au/a/national/everything/search/"
|
50
|
+
@search_term = search_term
|
51
|
+
@class_name = "products"
|
52
|
+
@all_products = ".product"
|
53
|
+
@check = ".product-name"
|
48
54
|
end
|
49
55
|
|
50
56
|
end
|
51
57
|
|
52
58
|
class CompareSupermarkets::WoolworthsScraper < CompareSupermarkets::Scraper
|
53
59
|
|
54
|
-
def
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
+
def initialize(search_term)
|
61
|
+
@supermarket = 'Woolworths'
|
62
|
+
@search = "https://www.woolworths.com.au/shop/search/products?searchTerm="
|
63
|
+
@search_term = search_term
|
64
|
+
@class_name = "layoutWrapper"
|
65
|
+
@all_products = ".shelfProductTile-content"
|
66
|
+
@check = ".shelfProductTile-descriptionLink"
|
60
67
|
end
|
61
68
|
|
62
69
|
end
|
@@ -2,22 +2,22 @@ class CompareSupermarkets::Supermarket
|
|
2
2
|
attr_accessor :name
|
3
3
|
|
4
4
|
@@all = []
|
5
|
+
@@products = []
|
5
6
|
|
6
7
|
def initialize(name=nil)
|
7
8
|
@name = name
|
8
9
|
@@all << self
|
9
|
-
@products = []
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.all
|
13
13
|
@@all
|
14
14
|
end
|
15
15
|
|
16
|
-
def self.
|
17
|
-
|
16
|
+
def self.all_products
|
17
|
+
@@products
|
18
18
|
end
|
19
19
|
|
20
|
-
def products
|
20
|
+
def self.products
|
21
21
|
CompareSupermarkets::Product.all.select{|product| product.supermarket == self}
|
22
22
|
end
|
23
23
|
|
@@ -25,38 +25,38 @@ class CompareSupermarkets::Supermarket
|
|
25
25
|
@@all.clear
|
26
26
|
end
|
27
27
|
|
28
|
+
def add_product
|
29
|
+
if @dollar_value != "0" && @cent_value != "0"
|
30
|
+
new_product = CompareSupermarkets::Product.new(@supermarket, @name, @price, @unit_size, @url, @dollar_value, @cent_value)
|
31
|
+
@@products << new_product
|
32
|
+
end
|
33
|
+
end
|
28
34
|
end
|
29
35
|
|
30
36
|
class CompareSupermarkets::Coles < CompareSupermarkets::Supermarket
|
31
37
|
|
32
|
-
def
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
new_product = CompareSupermarkets::Product.new(supermarket, name, price, unit_size, url, dollar_value, cent_value)
|
42
|
-
@products << new_product
|
43
|
-
end
|
38
|
+
def initialize(product)
|
39
|
+
@product = product
|
40
|
+
@supermarket = self
|
41
|
+
@name = @product.css(".product-name").text
|
42
|
+
@price = @product.css(".package-price").text.delete_prefix('$').gsub('per', '/')
|
43
|
+
@unit_size = @product.css(".package-size.accessibility-inline").text.chomp(' ')
|
44
|
+
@url = "https://shop.coles.com.au#{@product.css(".product-image-link").attribute('href')}"
|
45
|
+
@dollar_value = @product.css(".dollar-value").text
|
46
|
+
@cent_value = @product.css(".cent-value").text.delete_prefix('.')
|
44
47
|
end
|
45
48
|
end
|
46
49
|
|
47
50
|
class CompareSupermarkets::Woolworths < CompareSupermarkets::Supermarket
|
48
51
|
|
49
|
-
def
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
new_product = CompareSupermarkets::Product.new(supermarket, name, price, unit_size, url, dollar_value, cent_value)
|
59
|
-
@products << new_product
|
60
|
-
end
|
52
|
+
def initialize(product)
|
53
|
+
@product = product
|
54
|
+
@supermarket = self
|
55
|
+
@name = @product.css(".shelfProductTile-descriptionLink").text
|
56
|
+
@price = @product.css(".shelfProductTile-cupPrice.ng-star-inserted").text.delete_prefix(' $').chomp(" ")
|
57
|
+
@unit_size = @product.css(".shelfProductTile-descriptionLink").text.split(" ").last
|
58
|
+
@url = "https://www.woolworths.com.au#{@product.css(".shelfProductTile-descriptionLink").attribute('href').value}"
|
59
|
+
@dollar_value = @product.css(".price-dollars").text
|
60
|
+
@cent_value = @product.css(".price-cents").text
|
61
61
|
end
|
62
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.
|
4
|
+
version: 0.4.2
|
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-10-
|
11
|
+
date: 2021-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|