newegg_scraper_chsbr 0.1.3 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/environment.rb +2 -0
- data/lib/newegg_scraper_chsbr/cli.rb +75 -14
- data/lib/newegg_scraper_chsbr/cpu.rb +25 -7
- data/lib/newegg_scraper_chsbr/data_grabber.rb +32 -64
- data/lib/newegg_scraper_chsbr/name.rb +1 -1
- data/lib/newegg_scraper_chsbr/scraper.rb +1 -1
- data/lib/newegg_scraper_chsbr/user.rb +20 -7
- data/lib/newegg_scraper_chsbr/version.rb +1 -1
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f34ca8fd0dbc560e05743c291654c9bdd092cc8c30c534978898666fdad5eaa3
|
4
|
+
data.tar.gz: 55eec0e26900218bf9ad0ae8ae37c65863add7639365a3df818ece9625e0aaa9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b50c23b2586cb80492649ed42cfce04f1f1e099baa4d99ddf9539fcfd0b66013f989e47ed56fd2a6f2fc0f9fe8428a338ac6e5d0b16acd993acb6fc8c06f39a9
|
7
|
+
data.tar.gz: 1bf45a023b6508aa5c2bd90996928291667945e4c6e588c7776da5f5dbc6232e684f9f598fbc865b605d4fd9054d97b808fdb08554497c59e895297bb9d45b24
|
data/lib/environment.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
class NeweggScraperChsbr::CLI
|
3
2
|
attr_reader :user
|
4
3
|
def initialize
|
@@ -6,26 +5,54 @@ class NeweggScraperChsbr::CLI
|
|
6
5
|
end
|
7
6
|
def call
|
8
7
|
puts "Were you interested in purchasing some CPU's?"
|
9
|
-
puts "Please enter y to do so."
|
8
|
+
puts "Please enter y to do so."
|
10
9
|
@counter = gets.strip
|
11
|
-
|
10
|
+
corr_input = control_bool
|
11
|
+
while corr_input
|
12
|
+
puts "Were you interested in purchasing some CPU's?"
|
13
|
+
puts "Please enter y to do so.\nPlease enter n or exit to quit."
|
14
|
+
@counter = gets.strip
|
15
|
+
corr_input = control_bool
|
16
|
+
end
|
17
|
+
while @counter == 'y'
|
18
|
+
get_price_range
|
12
19
|
get_init_data_for_user
|
13
|
-
NeweggScraperChsbr::Cpu.display_cpu(@user)
|
14
|
-
|
20
|
+
printed_cpus = NeweggScraperChsbr::Cpu.display_cpu(@user)
|
21
|
+
|
22
|
+
|
23
|
+
@user.choose_cpu(printed_cpus)
|
24
|
+
|
25
|
+
|
15
26
|
NeweggScraperChsbr::Cpu.display_cpu_with_extras(@user)
|
16
|
-
puts "If you would like to
|
27
|
+
puts "If you would like to restart the program please enter : #{@counter}.\nTo exit type n or exit."
|
17
28
|
@counter = gets.strip
|
29
|
+
corr_input = control_bool
|
30
|
+
while corr_input
|
31
|
+
puts "Were you interested in purchasing some CPU's?"
|
32
|
+
puts "Please enter y to do so.\nPlease enter n or exit to quit."
|
33
|
+
@counter = gets.strip
|
34
|
+
corr_input = control_bool
|
35
|
+
end
|
36
|
+
|
18
37
|
end
|
19
38
|
puts "Thanks for using Chesbro's Scraper!"
|
20
39
|
end
|
21
40
|
def get_init_data_for_user
|
22
41
|
|
23
42
|
if @counter == 'y'
|
24
|
-
|
43
|
+
|
25
44
|
puts "Are you searching for Intel or AMD?"
|
26
45
|
puts "Please put i for Intel, or a for AMD."
|
27
46
|
puts "Please put x for either."
|
28
47
|
@cpu_make = gets.strip
|
48
|
+
not_found = cpu_make_bool
|
49
|
+
while not_found
|
50
|
+
puts "Are you searching for Intel or AMD?"
|
51
|
+
puts "Please put i for Intel, or a for AMD."
|
52
|
+
puts "Please put x for either."
|
53
|
+
@cpu_make = gets.strip
|
54
|
+
not_found = cpu_make_bool
|
55
|
+
end
|
29
56
|
puts "\n\nYou want to search for (an) #{NeweggScraperChsbr::Cpu.cpu_maker(@cpu_make)} CPU."
|
30
57
|
if @max_price.to_i != 0 && @min_price.to_i != 0
|
31
58
|
puts "You entered a maximum price of $#{@max_price}, and a minimum price of $#{@min_price}."
|
@@ -40,28 +67,62 @@ class NeweggScraperChsbr::CLI
|
|
40
67
|
end
|
41
68
|
end
|
42
69
|
def if_correct_info
|
43
|
-
puts "\nIf you're satisfied with your selection, the computer will print\na list of CPUs that satisfy the criteria. Enter y to continue."
|
70
|
+
puts "\nIf you're satisfied with your selection, the computer will print\na list of CPUs that satisfy the criteria. Enter y to continue. Enter n to choose again."
|
44
71
|
@counter = gets.strip
|
45
72
|
if @counter == 'y'
|
46
73
|
@user = NeweggScraperChsbr::User.new(@cpu_make, @min_price, @max_price)
|
47
74
|
else
|
48
|
-
|
75
|
+
@counter = 'y'
|
76
|
+
call
|
49
77
|
end
|
50
78
|
end
|
51
79
|
def get_price_range
|
52
80
|
puts "Welcome. Would you like to set a budget? If no, set your maximum budget to 0"
|
81
|
+
puts "Please enter the integer value of your maximum price."
|
82
|
+
puts "$500.50, please enter as 501, or 500 to stay below budget."
|
83
|
+
@max_price = gets.strip
|
84
|
+
while @max_price.to_i < 0 || @max_price.to_i > 10000 || @max_price.include?("$") || @max_price.include?(".") || @max_price == nil
|
85
|
+
puts "Welcome. Would you like to set a budget? If no, set your maximum budget to 0"
|
53
86
|
puts "Please enter the integer value of your maximum price."
|
54
87
|
puts "$500.50, please enter as 501, or 500 to stay below budget."
|
55
88
|
@max_price = gets.strip
|
56
|
-
|
57
|
-
|
58
|
-
|
89
|
+
end
|
90
|
+
if @max_price.to_i != 0
|
91
|
+
puts "Please enter the minimum you would spend on a CPU."
|
92
|
+
puts "Please use the same format as above."
|
93
|
+
@min_price = gets.strip
|
94
|
+
|
95
|
+
while @min_price.to_i <= 0 || @min_price.to_i >= @max_price.to_i || @min_price.include?("$") || @min_price.include?(".") || @min_price == nil
|
59
96
|
puts "Please enter the minimum you would spend on a CPU."
|
60
97
|
puts "Please use the same format as above."
|
61
98
|
@min_price = gets.strip
|
62
99
|
end
|
63
|
-
|
100
|
+
end
|
64
101
|
end
|
102
|
+
def control_bool
|
103
|
+
if @counter.include?("y")
|
104
|
+
false
|
105
|
+
elsif @counter.include?("exit")
|
106
|
+
false
|
107
|
+
elsif @counter.include?("n")
|
108
|
+
false
|
109
|
+
else
|
110
|
+
true
|
111
|
+
end
|
112
|
+
end
|
113
|
+
def cpu_make_bool
|
114
|
+
if @cpu_make.include?("x")
|
115
|
+
@cpu_make = "x"
|
116
|
+
false
|
117
|
+
elsif @cpu_make.include?("a")
|
118
|
+
@cpu_make = "a"
|
119
|
+
false
|
120
|
+
elsif @cpu_make.include?("i")
|
121
|
+
@cpu_make = "i"
|
122
|
+
false
|
123
|
+
else
|
124
|
+
true
|
125
|
+
end
|
65
126
|
|
66
|
-
|
127
|
+
end
|
67
128
|
end
|
@@ -6,7 +6,7 @@ class NeweggScraperChsbr::Cpu
|
|
6
6
|
@name = NeweggScraperChsbr::Name.new(name)
|
7
7
|
@price = NeweggScraperChsbr::Price.new(price)
|
8
8
|
@desc = NeweggScraperChsbr::Descriptors.new(desc)
|
9
|
-
@shipping =
|
9
|
+
@shipping = NeweggScraperChsbr::Shipping.new(shipping)
|
10
10
|
@@all << self
|
11
11
|
end
|
12
12
|
def self.all
|
@@ -23,32 +23,50 @@ class NeweggScraperChsbr::Cpu
|
|
23
23
|
end
|
24
24
|
def self.display_cpu(user)
|
25
25
|
counter = 1
|
26
|
+
printed_cpus = []
|
26
27
|
@@all.each do | computer |
|
27
28
|
if user.max_price.to_i != 0 && user.min_price.to_i == 0
|
28
|
-
|
29
|
+
|
29
30
|
|
30
31
|
user.min_price = "1"
|
31
32
|
end
|
32
33
|
if user.max_price.to_i == 0 &&
|
33
34
|
user.min_price.to_i == 0 &&
|
34
35
|
(NeweggScraperChsbr::Cpu.cpu_maker(user.cpu_make) == "Intel" || NeweggScraperChsbr::Cpu.cpu_maker(user.cpu_make) == "AMD")
|
35
|
-
computer.name.name.include?(NeweggScraperChsbr::Cpu.cpu_maker(user.cpu_make))
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
if computer.name.name.include?(NeweggScraperChsbr::Cpu.cpu_maker(user.cpu_make))
|
37
|
+
puts("\n #{counter}:\n Name: #{computer.name.name}\n Price: #{computer.price.price}")
|
38
|
+
printed_cpus << counter
|
39
|
+
else
|
40
|
+
nil
|
41
|
+
end
|
42
|
+
elsif user.max_price.to_i == 0 && user.min_price.to_i == 0 && user.cpu_make == 'x'
|
43
|
+
|
39
44
|
puts("\n #{counter}:\n Name: #{computer.name.name}\n Price: #{computer.price.price}")
|
45
|
+
printed_cpus << counter
|
40
46
|
elsif user.max_price.to_i >= computer.price.convert_price &&
|
41
47
|
user.min_price.to_i <= computer.price.convert_price &&
|
42
48
|
(NeweggScraperChsbr::Cpu.cpu_maker(user.cpu_make) == "Intel" || NeweggScraperChsbr::Cpu.cpu_maker(user.cpu_make) == "AMD")
|
43
|
-
computer.name.name.include?(NeweggScraperChsbr::Cpu.cpu_maker(user.cpu_make))
|
49
|
+
if computer.name.name.include?(NeweggScraperChsbr::Cpu.cpu_maker(user.cpu_make))
|
50
|
+
puts("\n #{counter}:\n Name: #{computer.name.name}\n Price: #{computer.price.price}")
|
51
|
+
printed_cpus << counter
|
52
|
+
else
|
53
|
+
nil
|
54
|
+
end
|
44
55
|
|
45
56
|
elsif user.max_price.to_i >= computer.price.convert_price &&
|
46
57
|
user.min_price.to_i <= computer.price.convert_price &&
|
47
58
|
user.cpu_make == 'x'
|
48
59
|
puts("\n #{counter}:\n Name: #{computer.name.name}\n Price: #{computer.price.price}")
|
60
|
+
printed_cpus << counter
|
61
|
+
|
62
|
+
elsif printed_cpus.size == 0
|
63
|
+
puts "You did not match any CPU criteria."
|
49
64
|
end
|
65
|
+
|
50
66
|
counter += 1
|
67
|
+
|
51
68
|
end
|
69
|
+
printed_cpus
|
52
70
|
|
53
71
|
end
|
54
72
|
def self.display_cpu_with_extras(user)
|
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
class NeweggScraperChsbr::DataGrabber
|
3
2
|
attr_reader :cpus
|
4
3
|
|
@@ -9,7 +8,7 @@ class NeweggScraperChsbr::DataGrabber
|
|
9
8
|
names = getNames
|
10
9
|
descHash = getCpuDesc
|
11
10
|
@cpus = makeCpus(prices, names, shipping_price, descHash)
|
12
|
-
end
|
11
|
+
end
|
13
12
|
|
14
13
|
def getCpuDesc
|
15
14
|
scraped = NeweggScraperChsbr::Scraper.new
|
@@ -18,7 +17,10 @@ class NeweggScraperChsbr::DataGrabber
|
|
18
17
|
css_next_link = scraped.xml_obj.css ".item-title"
|
19
18
|
css_next_link.each_with_index do | element, index |
|
20
19
|
if index != 0
|
21
|
-
|
20
|
+
|
21
|
+
if element.attributes["href"] != nil
|
22
|
+
pages << element.attributes["href"].text
|
23
|
+
end
|
22
24
|
end
|
23
25
|
end
|
24
26
|
description = {}
|
@@ -44,19 +46,19 @@ class NeweggScraperChsbr::DataGrabber
|
|
44
46
|
|
45
47
|
|
46
48
|
end
|
47
|
-
def split_price(html_element)
|
49
|
+
def split_price(html_element)
|
48
50
|
counter = 0
|
49
51
|
until counter == 100
|
50
|
-
if counter < 10
|
51
|
-
if html_element.text.include?(".0#{counter.to_s}")
|
52
|
-
|
53
|
-
price = html_element.text.split ".0#{counter.to_s}"
|
54
|
-
|
55
|
-
|
52
|
+
if counter < 10
|
53
|
+
if html_element.text.include?(".0#{counter.to_s}")
|
54
|
+
|
55
|
+
price = html_element.text.split ".0#{counter.to_s}"
|
56
|
+
|
57
|
+
|
56
58
|
price.delete_at 1
|
57
|
-
return price, ".0#{counter.to_s}"
|
59
|
+
return price, ".0#{counter.to_s}"
|
58
60
|
end
|
59
|
-
elsif counter >= 10
|
61
|
+
elsif counter >= 10
|
60
62
|
if html_element.text.include?(".#{counter.to_s}")
|
61
63
|
|
62
64
|
price = (html_element.text.split ".#{counter.to_s}")
|
@@ -67,59 +69,35 @@ class NeweggScraperChsbr::DataGrabber
|
|
67
69
|
counter += 1
|
68
70
|
end
|
69
71
|
end
|
70
|
-
def isCoolerOrMB?(name)
|
71
|
-
name.include?("Water") || name.include?("Air") || name.include?("Motherboard")
|
72
|
-
# any of the products include
|
73
|
-
# words that describe motherboards and/or
|
74
|
-
# cooling products.
|
72
|
+
def isCoolerOrMB?(name)
|
73
|
+
name.include?("Water") || name.include?("Air") || name.include?("Motherboard") || name.include?("AIO") || name.include?("FLY")
|
75
74
|
end
|
76
75
|
def getPrice
|
77
76
|
scraped_info = NeweggScraperChsbr::Scraper.new
|
78
|
-
css_price = scraped_info.xml_obj.css ".price-current"
|
79
|
-
# html that contains what I need to find the price.
|
77
|
+
css_price = scraped_info.xml_obj.css ".price-current"
|
80
78
|
|
81
|
-
prices = []
|
82
|
-
|
83
|
-
css_price.each do | piece | # Going 1 level deep into the html obj that contains the price text element.
|
84
|
-
|
85
|
-
temp_price = split_price piece # split_price will split the price, and return
|
86
|
-
# two variables in an array. The first element of
|
87
|
-
# the array will be the dollar amount.
|
88
|
-
# The second element will be the cent ammount because
|
89
|
-
# I deemed it easier to remove anything after the
|
90
|
-
# floating point, it was the only pattern that was
|
91
|
-
# consistent.
|
79
|
+
prices = []
|
92
80
|
|
81
|
+
css_price.each do | piece |
|
82
|
+
temp_price = split_price piece
|
93
83
|
if temp_price != nil
|
94
|
-
temp_price.flatten!
|
95
|
-
|
96
|
-
# to return the flattened array to temp_price.
|
97
|
-
|
98
|
-
prices << "#{temp_price[0]}#{temp_price[1]}" # Here prices is being shoveled the
|
99
|
-
# two elements, concatenated to create
|
100
|
-
# a string similar to "$00.00"
|
84
|
+
temp_price.flatten!
|
85
|
+
prices << "#{temp_price[0]}#{temp_price[1]}"
|
101
86
|
end
|
102
87
|
|
103
|
-
end
|
88
|
+
end
|
104
89
|
prices
|
105
90
|
end
|
106
91
|
def getNames
|
107
92
|
scraped = NeweggScraperChsbr::Scraper.new
|
108
|
-
names = []
|
109
|
-
# objects found on the page.
|
93
|
+
names = []
|
110
94
|
|
111
|
-
css_name = scraped.xml_obj.css ".item-title"
|
112
|
-
# object to be enumerated upon.
|
95
|
+
css_name = scraped.xml_obj.css ".item-title"
|
113
96
|
|
114
|
-
css_name.each_with_index do | name, index |
|
115
|
-
# to retrieve the strings.
|
97
|
+
css_name.each_with_index do | name, index |
|
116
98
|
|
117
|
-
index != 0 ? names << name.text : nil
|
118
|
-
|
119
|
-
# After I skip the first name
|
120
|
-
# I will shovel the text from the
|
121
|
-
# html object into the names array.
|
122
|
-
end #end names.each_with_index
|
99
|
+
index != 0 ? names << name.text : nil
|
100
|
+
end
|
123
101
|
names
|
124
102
|
end
|
125
103
|
def getShipping
|
@@ -136,23 +114,13 @@ class NeweggScraperChsbr::DataGrabber
|
|
136
114
|
|
137
115
|
|
138
116
|
cpus = []
|
139
|
-
prices.each_with_index do | price, index |
|
140
|
-
# each of the prices with their
|
141
|
-
# index so that the enumation can
|
142
|
-
# access the names array at the
|
143
|
-
# same time.
|
117
|
+
prices.each_with_index do | price, index |
|
144
118
|
|
145
|
-
if !isCoolerOrMB?(names[index])
|
146
|
-
# the name is a cooler
|
147
|
-
# or motherboard because
|
148
|
-
# there is a price associated
|
149
|
-
# with the coolers on the
|
150
|
-
# website.
|
151
|
-
|
119
|
+
if !isCoolerOrMB?(names[index])
|
152
120
|
cpus << NeweggScraperChsbr::Cpu.new(names[index], price, shipping[index], desc_hash[index])
|
153
121
|
|
154
|
-
end
|
155
|
-
end
|
122
|
+
end
|
123
|
+
end
|
156
124
|
cpus
|
157
125
|
end
|
158
126
|
end
|
@@ -4,7 +4,7 @@ class NeweggScraperChsbr::Scraper
|
|
4
4
|
|
5
5
|
URL = "https://www.newegg.com/p/pl?d=cpu"
|
6
6
|
def initialize(url = URL)
|
7
|
-
@xml_obj = Nokogiri::HTML(open(url))
|
7
|
+
@xml_obj = Nokogiri::HTML(URI.open(url))
|
8
8
|
end
|
9
9
|
|
10
10
|
|
@@ -7,14 +7,27 @@ class NeweggScraperChsbr::User
|
|
7
7
|
@max_price = max_price
|
8
8
|
@chosen_cpu = []
|
9
9
|
end
|
10
|
-
def choose_cpu
|
11
|
-
puts "Please enter the number of the CPU you'd like to
|
12
|
-
chosen = gets.strip
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
def choose_cpu(printed_cpus)
|
11
|
+
puts "Please enter the number of the CPU you'd like to see more about."
|
12
|
+
chosen = gets.strip
|
13
|
+
while !is_numeric?(chosen)
|
14
|
+
puts "Please enter the number of the CPU you'd like to see more about."
|
15
|
+
chosen = gets.strip
|
16
|
+
end
|
17
|
+
if !printed_cpus.include?(chosen.to_i)
|
18
|
+
puts "You chose a CPU outside of your budget please choose another."
|
19
|
+
choose_cpu(printed_cpus)
|
20
|
+
end
|
21
|
+
@chosen_cpu << chosen.to_i
|
22
|
+
puts "Would you like to see more about another CPU?\nEnter y to do so.\nEnter n to see details about the chosen CPU(s)"
|
23
|
+
input = gets.strip
|
24
|
+
|
25
|
+
if input == 'y'
|
26
|
+
choose_cpu(printed_cpus)
|
17
27
|
end
|
18
28
|
|
19
29
|
end
|
30
|
+
def is_numeric?(obj)
|
31
|
+
obj.match(/\A[^+-]?\d+?(\^.\d+)?\Z/) == nil ? false : true
|
32
|
+
end
|
20
33
|
end
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: newegg_scraper_chsbr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lrd134
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-04-
|
11
|
+
date: 2021-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.11.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.11.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: open-uri
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
33
|
+
version: '0.1'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
40
|
+
version: '0.1'
|
41
41
|
description: To scrape CPU's off of Newegg and display them nicely.
|
42
42
|
email:
|
43
43
|
- larryc3200@gmail.com
|