compare_supermarkets 0.2.1 → 0.3.0

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: 03a77c0e97c8e992eadc1d00e7d9da010e2a1d8bd60e8b50548161cd25417f17
4
- data.tar.gz: 98103223d9737ee4a5e256e5908b50fc62225b63465acdcdffaf7f6d9876603b
3
+ metadata.gz: 90604e8eb229da793fc7dce7dc6a8fef755c9641f26d970d5d4ada5dcdbcbcd2
4
+ data.tar.gz: 2592bf4d883462efb1969e4bf023144d78155ee54577ed0c0b1ad126bd517976
5
5
  SHA512:
6
- metadata.gz: 9b699078cc6395acc8af0781b0d9aed79cf2db7a20180d19c8f448986e92ed2f68b4e27a1dc3a5970451782b61d3f4ed6dae46a4bfbc7e38061fd7359f3e46e3
7
- data.tar.gz: 89901059141fa825b3e7c58a1e58301389b940c7ab16a397562934639e0f63b1b081c0ce7578ee04c758663a84ff2c606903fb3001493418bc8a54f0ed138c7c
6
+ metadata.gz: 802b23988e9318b64ad149be1e3d7121af694998fa3a0f756dac8221c4e6252dc076fc82ae1766861e78bc8f674a0f7d01cf044cc0c9d7d7152b44f1739b1eba
7
+ data.tar.gz: 755c1cc979a843ad2cfe0109ba27bde3e95c8c93ece83b74a08e7556ec19bdc138fee9206ddeac6764f3d4c4c08c638562eb357210c95fd442b0f31c24996d30
@@ -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 and Woolies? (Y/N)"
8
+ puts "Would you like to compare prices between Coles, Woolworths and IGA? (Y/N)"
9
9
  input = gets.strip.downcase
10
10
  puts ""
11
11
  if input == "y"
@@ -42,7 +42,7 @@ class CompareSupermarkets::CLI
42
42
  self.search_supermarkets(input)
43
43
  puts ""
44
44
  puts ""
45
- if CompareSupermarkets::Product.count > 10
45
+ if CompareSupermarkets::Product.count > 20
46
46
  puts ""
47
47
  puts "Ooo, jeez, seems like we have a lot of results."
48
48
  puts "We have #{CompareSupermarkets::Product.count} results for you."
@@ -111,6 +111,8 @@ class CompareSupermarkets::CLI
111
111
  puts ""
112
112
  puts "5 - Only Woolworths items"
113
113
  puts ""
114
+ puts "6 - Only IGA items"
115
+ puts ""
114
116
  input = gets.strip
115
117
  puts ""
116
118
  choice(input)
@@ -135,6 +137,10 @@ class CompareSupermarkets::CLI
135
137
  how_to_sort ? direction = "asc" : direction = "desc"
136
138
  choice = CompareSupermarkets::Product.woolworths_sorted_by_price
137
139
  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)
138
144
  elsif input == ""
139
145
  invalid_input
140
146
  how_to_display
@@ -10,7 +10,13 @@ class CompareSupermarkets::Product
10
10
  @unit_size = unit_size
11
11
  @dollar_value = dollar_value
12
12
  @cent_value = cent_value
13
- @url = @supermarket.name == "Coles" ? "https://shop.coles.com.au#{url}" : "https://www.woolworths.com.au#{url}"
13
+ @url = if @supermarket.name == "Coles"
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
14
20
  @@all << self
15
21
  end
16
22
 
@@ -54,6 +60,14 @@ class CompareSupermarkets::Product
54
60
  end
55
61
  end
56
62
 
63
+ def self.iga_sorted_by_price
64
+ iga_items = self.all.select{|product| product.supermarket_name == "IGA"}
65
+ iga_items.sort_by! do |s|
66
+ price_to_sort = s.dollar_value + '.' + s.cent_value
67
+ price_to_sort.to_f
68
+ end
69
+ end
70
+
57
71
  def self.clear_all
58
72
  @@all.clear
59
73
  end
@@ -9,6 +9,7 @@ class CompareSupermarkets::Scraper
9
9
  def self.search_supermarkets(search_term)
10
10
  self.search_coles_for(search_term)
11
11
  self.search_woolworths_for(search_term)
12
+ self.search_iga_for(search_term)
12
13
  end
13
14
 
14
15
  def self.search_coles_for(search_term)
@@ -25,12 +26,15 @@ class CompareSupermarkets::Scraper
25
26
  else
26
27
  coles_products = Nokogiri::HTML(coles_js_doc.inner_html)
27
28
  all_coles_products = coles_products.css(".product")
29
+ coles = CompareSupermarkets::Supermarket.new("Coles")
28
30
  all_coles_products.each do |product|
29
31
  if product.css(".product-name").text != ""
30
- coles = CompareSupermarkets::Supermarket.new("Coles")
31
32
  coles.add_product(product)
32
33
  end
33
34
  end
35
+ if coles.products.count == 0
36
+ puts "Coles do not have this product"
37
+ end
34
38
  ensure
35
39
  browser.close
36
40
  end
@@ -46,14 +50,41 @@ class CompareSupermarkets::Scraper
46
50
  else
47
51
  woolworths_products = Nokogiri::HTML(woolworths_js_doc.inner_html)
48
52
  woolworths_all_products = woolworths_products.css(".shelfProductTile-content")
53
+ woolworths = CompareSupermarkets::Supermarket.new("Woolworths")
49
54
  woolworths_all_products.each do |product|
50
55
  if product.css(".shelfProductTile-descriptionLink").text != ""
51
56
  if product.css(".unavailableSection.width-full.ng-star-inserted").empty?
52
- woolworths = CompareSupermarkets::Supermarket.new("Woolworths")
53
57
  woolworths.add_product(product)
54
58
  end
55
59
  end
56
60
  end
61
+ if woolworths.products.count == 0
62
+ puts "Woolworths do not have this product"
63
+ end
64
+ ensure
65
+ browser.close
66
+ end
67
+ end
68
+
69
+ def self.search_iga_for(search_term)
70
+ browser = Watir::Browser.new :chrome
71
+ browser.goto("https://new.igashop.com.au/sm/pickup/rsid/53363/results?q=#{search_term}")
72
+ begin
73
+ iga_js_doc = browser.element(class: ["Listing-sc-1vfhaq2", "iQljRa"]).wait_until(&:present?)
74
+ rescue
75
+ puts "iga does not have this product"
76
+ else
77
+ iga_products = Nokogiri::HTML(iga_js_doc.inner_html)
78
+ iga_all_products = iga_products.css(".ColListing-sc-lcurnl.kYBrWq")
79
+ iga = CompareSupermarkets::Supermarket.new("IGA")
80
+ iga_all_products.each do |product|
81
+ if product.css(".sc-hKFyIo.bdDYJz").text.downcase[search_term]
82
+ iga.add_product(product)
83
+ end
84
+ end
85
+ if iga.products.count == 0
86
+ puts "IGA do not have this product"
87
+ end
57
88
  ensure
58
89
  browser.close
59
90
  end
@@ -14,11 +14,11 @@ class CompareSupermarkets::Supermarket
14
14
  new_product = CompareSupermarkets::Product.new(self,
15
15
  product.css(".product-name").text,
16
16
  product.css(".package-price").text.delete_prefix('$').gsub('per', '/'),
17
- product.css(".package-size.accessibility-inline").text,
17
+ product.css(".package-size.accessibility-inline").text.chomp(' '),
18
18
  product.css(".product-image-link").attribute('href'),
19
19
  product.css(".dollar-value").text,
20
20
  product.css(".cent-value").text.delete_prefix('.'))
21
- else
21
+ elsif self.name == "Woolworths"
22
22
  new_product = CompareSupermarkets::Product.new(self,
23
23
  product.css(".shelfProductTile-descriptionLink").text,
24
24
  product.css(".shelfProductTile-cupPrice.ng-star-inserted").text.delete_prefix(' $').chomp(" "),
@@ -26,6 +26,20 @@ class CompareSupermarkets::Supermarket
26
26
  product.css(".shelfProductTile-descriptionLink").attribute('href').value,
27
27
  product.css(".price-dollars").text,
28
28
  product.css(".price-cents").text)
29
+ else
30
+ price_css = if product.css(".ProductCardPrice-sc-zgh1l1.hwVjs").text.delete_prefix("$").split(".").first
31
+ ".ProductCardPrice-sc-zgh1l1.hwVjs"
32
+ else
33
+ ".ProductCardPrice-sc-zgh1l1.jYaBFk"
34
+ end
35
+ new_product = CompareSupermarkets::Product.new(self,
36
+ product.css(".sc-hKFyIo.bdDYJz").text.split(', ').first,
37
+ product.css(".ProductCardPriceInfo-sc-1o21dmb.iDDqhD").text.delete_prefix("$").gsub("/", " / "),
38
+ product.css(".sc-hKFyIo.bdDYJz").text.split(', ').last,
39
+ product.css(".ProductCardHiddenLink-sc-y1ynto.hGUSDV").attribute('href').value,
40
+ product.css(price_css).text.delete_prefix("$").split(".").first,
41
+ product.css(price_css).text.split(".").last.chomp(" avg/ea")
42
+ )
29
43
  end
30
44
  @products << new_product
31
45
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CompareSupermarkets
4
- VERSION = "0.2.1"
4
+ VERSION = "0.3.0"
5
5
  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.2.1
4
+ version: 0.3.0
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-28 00:00:00.000000000 Z
11
+ date: 2021-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,8 +108,8 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: 3.142.7
111
- description: Will search Woolworths and Coles online stores for prices based on an
112
- input search parameter **Google Chrome Required**
111
+ description: Will search Woolworths, Coles and IGA online stores for prices based
112
+ on an input search parameter **Google Chrome Required**
113
113
  email:
114
114
  - happymelonbox@gmail.com
115
115
  executables: