shoe_scraper 0.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3bc84b5797462eeac2cb4eaad9b191d66cd4ca15b8060c3dc3b65a294a77f8ce
4
+ data.tar.gz: 60d02064a7076f3878bf3419391992639f14d93a457e96d67d2f8a32e38be140
5
+ SHA512:
6
+ metadata.gz: '09ed51b009e293313b0f9ad5f5228b395514970320509560e29af391e3f3c384de6c8cfcff71bfbfc4de7bba7a24d8283f07931ba2c164c1b2d73f60bd5cada3'
7
+ data.tar.gz: 67ce2f9e7544bc49a8bfbe1f915e62fd9ac9723702b39ce81aae2facbc880f59e236b29cfb3aeb58d3004c569f4227259474d1711042b70439f0db5b5aa98adf
@@ -0,0 +1,36 @@
1
+ class Jordan_Edition # Super
2
+
3
+ attr_accessor :name, :href, :shoe_collection
4
+
5
+ @@all = []
6
+
7
+ def initialize(hash)
8
+ hash.each_pair do |key, value|
9
+ send("#{key}=", value)
10
+ end
11
+ @@all << self
12
+ end
13
+
14
+ def self.create_from_collection(array_of_hash) #find or create would be better
15
+ array_of_hash.each do |hash|
16
+ self.new(hash)
17
+ end
18
+ end
19
+
20
+ def self.all
21
+ @@all
22
+ end
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+ end
@@ -0,0 +1,27 @@
1
+
2
+ class Brand #< Super
3
+
4
+ attr_accessor :brand_name, :brand_href, :editions, :edition_href, :shoe_collection
5
+
6
+ @@all = []
7
+
8
+ def initialize(hash)
9
+ hash.each do |key, value|
10
+ send("#{key}=", value)
11
+ end
12
+ @@all << self
13
+ end
14
+
15
+ def self.create_from_collection(array_of_hash)
16
+ array_of_hash.each do |hash|
17
+ self.new(hash)
18
+ end
19
+ end
20
+
21
+ def self.all
22
+ @@all
23
+ end
24
+
25
+ end
26
+
27
+
@@ -0,0 +1,106 @@
1
+
2
+ require 'open-uri'
3
+ require 'nokogiri'
4
+ require 'pry'
5
+ #URI.open("https://www.indexpdx.com/adidas/?sort=newest&page=1")
6
+
7
+ class IndexPDX_Scraper
8
+
9
+
10
+ def self.brand_list(index_url)
11
+ doc = Nokogiri::HTML(open(index_url))
12
+ doc.css(".BlockContent .SubCategoryList li").map do |brand|
13
+ hash = {}
14
+ hash[:brand_name] = brand.css("a").first.text
15
+ hash[:brand_href] = index_url.gsub("/adidas/", brand.css("a").first['href'])
16
+ unless hash[:brand_name].include?("Jason Markk")
17
+ end
18
+ binding.pry
19
+ hash
20
+ end
21
+ end
22
+
23
+ def self.brand_list(index_url)
24
+ array = []
25
+ doc = Nokogiri::HTML(open(index_url))
26
+ doc.css(".BlockContent .SubCategoryList li").each do |brand|
27
+
28
+ hash = {}
29
+
30
+ hash[:brand_name] = brand.css("a").first.text
31
+ hash[:brand_href] = index_url.gsub("/adidas/", brand.css("a").first['href'])
32
+ array << hash unless hash[:brand_name].include?("Jason Markk")
33
+ end
34
+ array
35
+ end
36
+
37
+
38
+ def self.scrape_jordans_index_page(index_url)
39
+ doc = Nokogiri::HTML(open(index_url))
40
+ doc.css(".jordans.clearfix a").map do |editions|
41
+ hash = {}
42
+ hash[:name] = editions.css(".jordan-edition p").first.text
43
+ hash[:href] = index_url.gsub("/jordans/", editions.first.last)
44
+ hash
45
+ end
46
+ end
47
+
48
+
49
+ #scrape all the shoes available for specific brand => array
50
+ def self.scrape_brand_index_page_one(index_url)
51
+ doc = Nokogiri::HTML(open(index_url))
52
+ doc.css(".ProductList li").map do |shoe|
53
+ hash = {}
54
+ hash[:shoe_name] = shoe.css(".ProductDetails a").first.text
55
+ hash[:price] = shoe.css(".ProductPriceRating em").text
56
+ hash[:shoe_href] = shoe.css(".ProductDetails a").first['href']
57
+ hash
58
+ end
59
+ end
60
+
61
+ def self.shoe_details(index_url)
62
+ details = Nokogiri::HTML(open(index_url))
63
+ hash = {}
64
+ details.css(".ProductDetailsGrid").each do |detail|
65
+ hash[:shoe_name] = details.css("h1").text
66
+ hash[:brand] = details.css(".specs span")[0].text
67
+ hash[:condition] = details.css(".specs span")[1].text
68
+ hash[:colorway] = details.css(".specs span")[2].text
69
+ hash[:year] = details.css(".specs span")[3].text
70
+ hash[:productid] = details.css(".specs span")[4].text
71
+ hash[:sizes_available] = details.css(".list-horizontal .name").map { |sizes| sizes.text }.join(', ')
72
+ end
73
+ hash
74
+ end
75
+
76
+
77
+ end
78
+
79
+
80
+
81
+ # #scrape the list of brands => array of hashes - WORKS
82
+ # def self.brand_list(index_url)
83
+
84
+ # doc = Nokogiri::HTML(open(index_url))
85
+ #
86
+ # doc.css(".BlockContent .SubCategoryList li").map do |brand|
87
+ # hash = {}
88
+
89
+ # hash[:brand_name] = brand.css("a").first.text
90
+ # hash[:brand_href] = index_url.gsub("/adidas/", brand.css("a").first['href'])
91
+ # hash
92
+
93
+ # end
94
+ # end
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+ # #details2 = Nokogiri::HTML(open("https://www.indexpdx.com/pw-human-race-nmd-solar/"))
104
+ # #page = URI.open("https://www.indexpdx.com/adidas/?sort=newest")
105
+ # # doc = Nokogiri::HTML(open(page))
106
+ # #doc = Nokogiri::HTML(open(https://www.indexpdx.com/adidas/?sort=newest))
@@ -0,0 +1,33 @@
1
+
2
+ class Shoe
3
+
4
+ attr_accessor :shoe_name, :price, :shoe_href, :brand, :condition, :colorway, :year, :productid, :sizes_available
5
+
6
+ @@all = []
7
+
8
+ def initialize(hash)
9
+ hash.each do |key, value|
10
+ send("#{key}=", value)
11
+ end
12
+ @@all.unshift(self)
13
+ end
14
+
15
+
16
+ def self.create_from_collection(array_of_hash)
17
+ array_of_hash.each do |hash|
18
+ self.new(hash)
19
+ end
20
+ end
21
+
22
+ def self.all
23
+ @@all
24
+ end
25
+
26
+ def add_attributes(hash)
27
+ hash.each do |key, value|
28
+ send("#{key}=", value)
29
+ end
30
+ end
31
+
32
+
33
+ end
@@ -0,0 +1,232 @@
1
+ # require 'rainbow/ext/string'
2
+ require_relative './super'
3
+ require_relative './brand'
4
+ require_relative './scraper'
5
+ require_relative './shoe'
6
+ require_relative './Jordan_Edition'
7
+
8
+ class ShoeScraper
9
+
10
+ BASE_PATH = "https://www.indexpdx.com/adidas/"
11
+
12
+ @@saved = []
13
+
14
+ def run
15
+ first_selection
16
+ end
17
+
18
+ def first_selection
19
+ # a = AsciiArt.new("https://www.indexpdx.com/content/images/logo.jpeg")
20
+ # print "#{a.to_ascii_art(width: 50)}"
21
+ puts ''
22
+ puts "Welcome to The Sneaker Finder! Are you ready to find your next pair of kicks?".colorize(:green)
23
+ puts ''
24
+ puts "Type yes or any other key to exit"
25
+
26
+ input = gets.chomp.downcase
27
+ if input == 'y'
28
+ # Saved_Shoe.new
29
+ puts ''
30
+ puts "Great!! Let's get you started with our list of brands".colorize(:green)
31
+ puts ''
32
+ scrape_brand
33
+ else
34
+ puts "Goodbye!".colorize(:green)
35
+ end
36
+ end
37
+
38
+ def scrape_brand
39
+
40
+ Brand.create_from_collection(IndexPDX_Scraper.brand_list(BASE_PATH))
41
+ display_brand
42
+ end
43
+
44
+ def display_brand
45
+ Brand.all.each.with_index(1) { |shoe_object, index| puts "#{index}. #{shoe_object.brand_name.colorize(:cyan)}"}
46
+ puts ""
47
+ puts "Alot to choose from! Let me know which one you want to see more of!".colorize(:green)
48
+ puts ""
49
+ select_brand
50
+ end
51
+
52
+ def select_brand #SELECT BRAND - FIND BRAND
53
+ puts "Enter a number..."
54
+ input = gets.chomp
55
+
56
+ if !input.to_i.between?(1, Brand.all.size) #1.Repeat select_brand function if input an index in the length of Brand.all
57
+ puts ""
58
+ puts "That is not a valid option."
59
+ puts ""
60
+ select_brand
61
+ else
62
+ href = Brand.all[input.to_i - 1].brand_href
63
+ if input == '1' #1.If they are Jordans, check if they have been scraped before
64
+ if Brand.all[input.to_i - 1].editions == nil
65
+ scrape_jordan_editions(href, input)
66
+ else
67
+ display_jordan_editions
68
+ end
69
+ elsif Brand.all[input.to_i - 1].shoe_collection == nil #1.If they are other shoes, check if they have been scraped before
70
+ scrape_shoe_collection(href, input)
71
+ else
72
+ display_shoe_collection(Brand.all[input.to_i - 1].shoe_collection)
73
+ end
74
+ end
75
+ end
76
+
77
+ #---------------------------------------------------------------------------
78
+
79
+ def scrape_shoe_collection(href, input)
80
+ scraper = IndexPDX_Scraper.scrape_brand_index_page_one(href)
81
+ Shoe.create_from_collection(scraper)
82
+ Brand.all[input.to_i - 1].shoe_collection= Shoe.all[0...scraper.size]
83
+ display_shoe_collection(Brand.all[input.to_i - 1].shoe_collection)
84
+ end
85
+
86
+ def display_shoe_collection(brand)
87
+ puts ''
88
+ brand.each.with_index(1) do |shoe_obj, index|
89
+ puts "#{index}. Model: #{shoe_obj.shoe_name.colorize(:cyan)}" + " Price: #{shoe_obj.price.colorize(:cyan)}".gsub("+", " ")
90
+ puts ""
91
+ end
92
+ select_shoe_collection
93
+ end
94
+
95
+ def scrape_edition_collection(href, input)
96
+ scraper = IndexPDX_Scraper.scrape_brand_index_page_one(href)
97
+ Shoe.create_from_collection(scraper)
98
+ Brand.all[0].editions[input.to_i - 1].shoe_collection = Shoe.all[0...scraper.size]
99
+ display_shoe_collection(Brand.all[0].editions[input.to_i - 1].shoe_collection)
100
+ end
101
+
102
+ def select_shoe_collection
103
+ puts "Gotta love some fresh kicks!! Pick a shoe and I can show you more info.".colorize(:green)
104
+ puts ""
105
+ puts "Type a number or 'b' for back"
106
+ input = gets.chomp.downcase
107
+
108
+ if input == "b"
109
+ display_brand
110
+ else
111
+ puts "Good Choice!".colorize(:green)
112
+ puts ''
113
+ scrape_shoe(input)
114
+ end
115
+ end
116
+
117
+ def scrape_jordan_editions(href, input)
118
+ Jordan_Edition.create_from_collection(IndexPDX_Scraper.scrape_jordans_index_page(href))
119
+ Brand.all[input.to_i - 1].editions= Jordan_Edition.all
120
+ display_jordan_editions
121
+ end
122
+
123
+ def display_jordan_editions
124
+ # a = AsciiArt.new("https://simg.nicepng.com/png/small/558-5587064_jordan2-air-jordan-logo-blue.png")
125
+ # print "#{a.to_ascii_art(width: 30)}"
126
+
127
+ puts ''
128
+ Jordan_Edition.all.each.with_index(1) { |edition, index| puts "#{index}." + "Jordan #{edition.name}".colorize(:cyan)}
129
+ # Brand.all.first.editions.each.with_index(1) do |edition, index|
130
+ # # #Brand.all[input.to_i - 1].editions.each.with_index(1) do |edition, index|
131
+ # puts "#{index}. Jordan #{edition.name.colorize(:green)}"
132
+ # end
133
+ select_jordan_editions
134
+ end
135
+
136
+ def select_jordan_editions
137
+ puts ''
138
+ puts "You can't go wrong with a pair of Jordans!".colorize(:green)
139
+ puts ""
140
+ puts "Type a number of 'b' for back."
141
+ puts ""
142
+ input = gets.chomp.downcase
143
+ href = Brand.all[0].editions[input.to_i - 1].href
144
+ if input == "b" #1.Go Back to brand menu. 2.Show Jordan edition either by scraping first or just displaying
145
+ display_brand
146
+ elsif Brand.all[0].editions[input.to_i - 1].shoe_collection == nil
147
+ scrape_edition_collection(href, input)
148
+ else
149
+ display_shoe_collection(Brand.all[0].editions[input.to_i - 1].shoe_collection)
150
+ end
151
+ end
152
+
153
+ def scrape_shoe(input)
154
+ Shoe.all[input.to_i - 1].add_attributes(IndexPDX_Scraper.shoe_details(Shoe.all[input.to_i - 1].shoe_href))
155
+ display_shoe(input)
156
+ end
157
+
158
+ def display_shoe(input)
159
+ puts "Brand: #{Shoe.all[input.to_i - 1].brand.colorize(:cyan)}"
160
+ puts "Name: #{Shoe.all[input.to_i - 1].shoe_name.colorize(:cyan)}"
161
+ puts "Colorway: #{Shoe.all[input.to_i - 1].colorway.colorize(:cyan)}"
162
+ puts "Condition: #{Shoe.all[input.to_i - 1].condition.colorize(:cyan)}"
163
+ puts "Year: #{Shoe.all[input.to_i - 1].year.colorize(:cyan)}"
164
+ puts "Price: #{Shoe.all[input.to_i - 1].price.colorize(:cyan)}".gsub("+", " ")
165
+
166
+ puts "Sizes Available: #{Shoe.all[input.to_i - 1].sizes_available.colorize(:cyan)}"
167
+ save(input)
168
+ end
169
+
170
+ def save(input)
171
+ puts ''
172
+ puts "Would you like to save this shoe?".colorize(:yellow)
173
+ choice = gets.chomp.downcase
174
+ if choice == 'y'
175
+ @@saved << Shoe.all[input.to_i - 1]
176
+ puts ''
177
+ puts "SHOE SAVED!!!!".colorize(:yellow)
178
+ puts ''
179
+ go_back
180
+ else
181
+ go_back
182
+ end
183
+ end
184
+
185
+ def go_back
186
+ puts ''
187
+ puts "Would you like to check out more? Type yes, cart, or exit".colorize(:green)
188
+ puts ''
189
+ input = gets.chomp.downcase
190
+ if input == 'y'
191
+ puts ''
192
+ display_brand
193
+ elsif input == 'c'
194
+ view_saved
195
+ elsif input == 'e'
196
+ puts ''
197
+ puts 'Goodbye!!'.colorize(:green)
198
+ puts ''
199
+ end
200
+ end
201
+
202
+ def view_saved
203
+ if @@saved.size == 0
204
+ puts ''
205
+ puts 'Your cart is empty.'.colorize(:green)
206
+ puts ''
207
+ go_back
208
+ else
209
+ puts ''
210
+ puts "////////////////////////////////////////////////////////////////////////////////////////////////////////////////".colorize(:yellow)
211
+ puts "////////////////////////////////////////////////////////////////////////////////////////////////////////////////".colorize(:yellow)
212
+ puts ''
213
+ @@saved.each do |shoe|
214
+ puts "Brand: #{shoe.brand.colorize(:cyan)}"
215
+ puts "Name: #{shoe.shoe_name.colorize(:cyan)}"
216
+ puts "Colorway: #{shoe.colorway.colorize(:cyan)}"
217
+ puts "Condition: #{shoe.condition.colorize(:cyan)}"
218
+ puts "Year: #{shoe.year.colorize(:cyan)}"
219
+ puts "Price: #{shoe.price.colorize(:cyan)}".gsub("+", " ")
220
+ puts "Sizes Available: #{shoe.sizes_available.colorize(:cyan)}"
221
+ puts "Web Link: #{shoe.shoe_href.colorize(:cyan)}"
222
+ puts ''
223
+ end
224
+ puts "////////////////////////////////////////////////////////////////////////////////////////////////////////////////".colorize(:yellow)
225
+ puts "////////////////////////////////////////////////////////////////////////////////////////////////////////////////".colorize(:yellow)
226
+ puts ''
227
+ puts "Here is your cart. Copy these for later. ".colorize(:green)
228
+ puts ''
229
+ go_back
230
+ end
231
+ end
232
+ end
@@ -0,0 +1,23 @@
1
+ class Super
2
+
3
+ @@all = []
4
+
5
+ def initialize(hash)
6
+ hash.each do |key, value|
7
+ send("#{key}=", value)
8
+ end
9
+ @@all << self
10
+ end
11
+
12
+ def self.create_from_collection(array_of_hash)
13
+ array_of_hash.each do |hash|
14
+ self.new(hash)
15
+ end
16
+ end
17
+
18
+
19
+ def self.all
20
+ @@all
21
+ end
22
+
23
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shoe_scraper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Uriah Harston
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2010-04-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A gem that scrapes available sneaker inventory from the indexpdx.com
14
+ shoe consignment website.
15
+ email: uharston@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/Jordan_Edition.rb
21
+ - lib/brand.rb
22
+ - lib/scraper.rb
23
+ - lib/shoe.rb
24
+ - lib/shoe_scraper.rb
25
+ - lib/super.rb
26
+ homepage: https://rubygems.org/gems/shoe_scraper
27
+ licenses:
28
+ - MIT
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubygems_version: 3.0.8
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: A sneaker finder gem
49
+ test_files: []