price_pulse 0.1.0 → 0.1.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: 7d14d7f47fc538678f2e647eca28845f57d6c14fb5c90183cc6df53699638c4a
|
|
4
|
+
data.tar.gz: f981f057e86bbbf4dc53c29ec24d136baa88974f1b2156666b8a080bff710de5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a1ffbe7b4a055b940bc092fb38a493ab9c2bf817c87796a0430ba13654c816032807c0268f045a5a404e28ea381f0ad22ceb76dee8a2a78cc29a8c5695ecb0ac
|
|
7
|
+
data.tar.gz: f39f5a5d19c0e4f315389e451862186604c2da31c11e77bb168c1f4a5ca27bbcb19d2fe8c2d394bd2bbb6abbd6e77d821f246b59e51a75ca47eb41c0506d06dc
|
|
@@ -1,76 +1,74 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "net/http"
|
|
4
|
-
require "nokogiri"
|
|
5
|
-
require "openssl"
|
|
6
|
-
|
|
7
|
-
module PricePulse
|
|
8
|
-
class Tracker
|
|
9
|
-
def initialize(items)
|
|
10
|
-
@items = items
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def compare_prices(item_name)
|
|
14
|
-
target_price = @items[item_name]
|
|
15
|
-
return "Item not found." unless target_price
|
|
16
|
-
|
|
17
|
-
full_prices = get_prices(item_name)
|
|
18
|
-
|
|
19
|
-
#
|
|
20
|
-
numerical_prices = full_prices.reject { |key, value| key == "Source (Title)" }
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
report << " =>
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
url_base = "https://en.wikipedia.org/wiki
|
|
47
|
-
uri = URI.parse(url_base)
|
|
48
|
-
|
|
49
|
-
# 2. Execute the live web request
|
|
50
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
|
51
|
-
http.use_ssl = true
|
|
52
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
53
|
-
response = http.request_get(uri.request_uri)
|
|
54
|
-
|
|
55
|
-
# 3. Define the simulated HTML body for price parsing
|
|
56
|
-
html_body = "<html><body><div id='price'>$#{item_name == 'Coffee Maker' ? 170.0 : 85.0}</div></body></html>"
|
|
57
|
-
|
|
58
|
-
# 4. Use Nokogiri to parse the simulated HTML
|
|
59
|
-
doc = Nokogiri::HTML(html_body)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
"
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
end
|
|
75
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "net/http"
|
|
4
|
+
require "nokogiri"
|
|
5
|
+
require "openssl" # Required for SSL bypass
|
|
6
|
+
|
|
7
|
+
module PricePulse
|
|
8
|
+
class Tracker
|
|
9
|
+
def initialize(items)
|
|
10
|
+
@items = items
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def compare_prices(item_name)
|
|
14
|
+
target_price = @items[item_name]
|
|
15
|
+
return "Item not found." unless target_price
|
|
16
|
+
|
|
17
|
+
full_prices = get_prices(item_name)
|
|
18
|
+
|
|
19
|
+
# 1. Filter out non-numerical data (like the page title)
|
|
20
|
+
numerical_prices = full_prices.reject { |key, value| key == "Source (Title)" }
|
|
21
|
+
|
|
22
|
+
# 2. Find the best price and shop
|
|
23
|
+
best_price = numerical_prices.values.min
|
|
24
|
+
best_shop = numerical_prices.key(best_price)
|
|
25
|
+
|
|
26
|
+
report = ["--- Tracking: #{item_name} (Target: $#{target_price}) ---"]
|
|
27
|
+
|
|
28
|
+
# List all prices, including the live title
|
|
29
|
+
full_prices.each { |shop, price| report << " - #{shop} price: #{price.is_a?(String) ? price : "$#{price}"}" }
|
|
30
|
+
|
|
31
|
+
if best_price < target_price
|
|
32
|
+
report << " => **DEAL!** Below target price of $#{target_price}"
|
|
33
|
+
else
|
|
34
|
+
report << " => Price is currently $#{best_price}, waiting for a better deal."
|
|
35
|
+
end
|
|
36
|
+
report << "Best Current Price Found: $#{best_price} at #{best_shop}"
|
|
37
|
+
report.join("\n")
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
private
|
|
41
|
+
|
|
42
|
+
def get_prices(item_name)
|
|
43
|
+
# 1. Define the URL dynamically using the item_name
|
|
44
|
+
# The gsub replaces spaces with underscores, a common URL convention.
|
|
45
|
+
wiki_item_name = item_name.gsub(' ', '_')
|
|
46
|
+
url_base = "https://en.wikipedia.org/wiki/#{wiki_item_name}"
|
|
47
|
+
uri = URI.parse(url_base)
|
|
48
|
+
|
|
49
|
+
# 2. Execute the live web request with SSL bypass
|
|
50
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
51
|
+
http.use_ssl = true
|
|
52
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
53
|
+
response = http.request_get(uri.request_uri)
|
|
54
|
+
|
|
55
|
+
# 3. Define the simulated HTML body for price parsing
|
|
56
|
+
html_body = "<html><body><div id='price'>$#{item_name == 'Coffee Maker' ? 170.0 : 85.0}</div></body></html>"
|
|
57
|
+
|
|
58
|
+
# 4. Use Nokogiri to parse the simulated HTML
|
|
59
|
+
doc = Nokogiri::HTML(html_body)
|
|
60
|
+
parsed_price = doc.at('#price').text.strip.delete('$').to_f
|
|
61
|
+
|
|
62
|
+
# 5. Extract the main title from the live response (to confirm live fetch worked)
|
|
63
|
+
live_doc = Nokogiri::HTML(response.body)
|
|
64
|
+
page_title = live_doc.at('h1').text.strip
|
|
65
|
+
|
|
66
|
+
# Return the parsed and live data
|
|
67
|
+
{
|
|
68
|
+
"Source (Title)" => page_title,
|
|
69
|
+
"Shop A (Simulated Price)" => parsed_price,
|
|
70
|
+
"Shop B (Hardcoded Price)" => item_name == 'Coffee Maker' ? 149.0 : 79.0
|
|
71
|
+
}
|
|
72
|
+
end
|
|
73
|
+
end
|
|
76
74
|
end
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "price_pulse/tracker"
|
|
4
|
-
|
|
5
|
-
module PricePulse
|
|
6
|
-
VERSION = "0.1.0"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "price_pulse/tracker"
|
|
4
|
+
|
|
5
|
+
module PricePulse
|
|
6
|
+
VERSION = "0.1.0"
|
|
7
|
+
class Error < StandardError; end
|
|
8
|
+
|
|
9
|
+
def self.status
|
|
10
|
+
"PricePulse is running version #{VERSION}"
|
|
11
|
+
end
|
|
13
12
|
end
|
data/price_pulse.gemspec
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
VERSION = "0.1.
|
|
4
|
-
|
|
5
|
-
Gem::Specification.new do |spec|
|
|
6
|
-
spec.name = "price_pulse"
|
|
7
|
-
spec.version
|
|
8
|
-
spec.authors = ["Your Name"]
|
|
9
|
-
spec.email = ["your@email.com"]
|
|
10
|
-
|
|
11
|
-
spec.summary = "A Ruby Gem for tracking and mapping prices from various sources."
|
|
12
|
-
spec.description = "The PricePulse gem provides a structured way to handle price data collection and analysis."
|
|
13
|
-
spec.homepage = "https://
|
|
14
|
-
spec.license = "MIT"
|
|
15
|
-
spec.required_ruby_version = ">= 2.7.0"
|
|
16
|
-
|
|
17
|
-
spec.files = Dir.glob("lib/**/*") + %w(price_pulse.gemspec)
|
|
18
|
-
spec.bindir = "exe"
|
|
19
|
-
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
spec.add_dependency "nokogiri", "~> 1.15"
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
VERSION = "0.1.2" # Version defined directly here
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "price_pulse"
|
|
7
|
+
spec.version = VERSION
|
|
8
|
+
spec.authors = ["Your Name"]
|
|
9
|
+
spec.email = ["your@email.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "A Ruby Gem for tracking and mapping prices from various sources."
|
|
12
|
+
spec.description = "The PricePulse gem provides a structured way to handle price data collection and analysis."
|
|
13
|
+
spec.homepage = "https://github.com/your-username/price_pulse"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
spec.required_ruby_version = ">= 2.7.0"
|
|
16
|
+
|
|
17
|
+
spec.files = Dir.glob("lib/**/*") + %w(price_pulse.gemspec)
|
|
18
|
+
spec.bindir = "exe"
|
|
19
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
20
|
+
|
|
21
|
+
spec.require_paths = ["lib"]
|
|
22
|
+
|
|
23
|
+
spec.add_dependency "nokogiri", "~> 1.15"
|
|
24
24
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: price_pulse
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Your Name
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: nokogiri
|
|
@@ -32,14 +31,13 @@ executables: []
|
|
|
32
31
|
extensions: []
|
|
33
32
|
extra_rdoc_files: []
|
|
34
33
|
files:
|
|
35
|
-
- lib/
|
|
36
|
-
- lib/
|
|
34
|
+
- lib/price_pulse.rb
|
|
35
|
+
- lib/price_pulse/tracker.rb
|
|
37
36
|
- price_pulse.gemspec
|
|
38
|
-
homepage: https://
|
|
37
|
+
homepage: https://github.com/your-username/price_pulse
|
|
39
38
|
licenses:
|
|
40
39
|
- MIT
|
|
41
40
|
metadata: {}
|
|
42
|
-
post_install_message:
|
|
43
41
|
rdoc_options: []
|
|
44
42
|
require_paths:
|
|
45
43
|
- lib
|
|
@@ -54,8 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
54
52
|
- !ruby/object:Gem::Version
|
|
55
53
|
version: '0'
|
|
56
54
|
requirements: []
|
|
57
|
-
rubygems_version: 3.
|
|
58
|
-
signing_key:
|
|
55
|
+
rubygems_version: 3.6.9
|
|
59
56
|
specification_version: 4
|
|
60
57
|
summary: A Ruby Gem for tracking and mapping prices from various sources.
|
|
61
58
|
test_files: []
|