popular_deals 0.2.5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c1fbdd67560c1af4af3b290d4a092988bd3a553
4
- data.tar.gz: b192d0609f4d0cef3c952ad98cc2e3e31f1d19e4
3
+ metadata.gz: 3a43dbe1d3b01ad6755ea411aa680796f77e79a2
4
+ data.tar.gz: 2f162330bfd2cf1c22dda273f58833ddff5722b0
5
5
  SHA512:
6
- metadata.gz: 0841d7a651d31807c94893f96b8da0eed9f1ebed32fd1522ab26a3d91bef5142a3c88d5fef84993e9bc7cec83e3719f9d2c313e9966e39e3b1d501830c2040cb
7
- data.tar.gz: a59e9c7470ba4a375c158cbae608d191886a483d2852412c9fc24986f66d61a56b3d2156e2f4b5dd6c74419d8fce4edf73ac62870188b24d32a48ad721c71774
6
+ metadata.gz: 7aa1637cbe6b72d4dd7622c19fd87dddd40a1062b8ae3b5cdcc056c864ece001696f38867faacfa97b6de94a103470c2fabb2be373f7ec9b2b9725b3311adc9c
7
+ data.tar.gz: 403689a17959097fc64ef4c71950645ad37f4d8bdc29dec0349bb6578db06e8afb51c43dc26dca023315cbcefa8ac2a3edd0e0bea7622ff3e5a122e49bf2bbd0
@@ -1,6 +1,7 @@
1
1
  require 'open-uri'
2
2
  require 'nokogiri'
3
3
  require 'colorize'
4
+ require 'pry'
4
5
 
5
6
 
6
7
 
@@ -1,36 +1,79 @@
1
1
  #CLI Controller
2
2
  class PopularDeals::CLI
3
-
3
+ BASE_URL = "https://slickdeals.net/deals/"
4
+ PAGE2_URL = "https://slickdeals.net/deals/?page=2&sort=recent"
5
+ PAGE3_URL = "https://slickdeals.net/deals/?page=3&sort=recent"
6
+ PAGE4_URL = "https://slickdeals.net/deals/?page=4&sort=recent"
7
+ PAGE5_URL = "https://slickdeals.net/deals/?page=5&sort=recent"
4
8
  attr_accessor :product_url
5
9
  #BROWSER=(/usr/local/bin/firefox-bin -new-tab '%s':/usr/local/bin/google-chrome-stable)
6
10
 
7
11
  def call
12
+ select_list_of_deals
8
13
  list_deals
9
14
  menu
15
+ #goodbye
10
16
  end
11
17
 
12
- def list_deals
18
+ def select_list_of_deals
13
19
  puts ""
14
- puts "Today's popular deals are:".upcase.yellow
20
+ puts "Which list of the deals would you like to see?".upcase.cyan.bold
21
+ puts "Type 1 for the first list of 1-20 deals.".yellow
22
+ puts "Type 2 for the second list of 21-40 deals.".yellow
23
+ puts "Type 3 for the third list of 41-60 deals.".yellow
24
+ puts "Type 4 for the fourth list of 61-80 deals.".yellow
25
+ puts "Type 5 for the fifth list of 81-100 deals.".yellow
15
26
  puts ""
16
- @deals = PopularDeals::NewDeals.new_deals
17
- @deals.each do |info|
18
- info.each.with_index(1) do |deal, i|
19
- if i < 10
20
- puts "#{i}. #{deal.title}".cyan.bold
21
- puts "Deal rating: #{deal.deal_rating}.".gsub(/^/, " ")
22
- puts "Deal value - #{deal.price}".gsub(/^/, " ")
23
- puts "#{deal.posted}".gsub(/^/, " ")
24
- puts ""
25
- elsif i >= 10
26
- puts "#{i}. #{deal.title}".cyan.bold
27
- puts "Deal rating: #{deal.deal_rating}.".gsub(/^/, " ")
28
- puts "Deal value - #{deal.price}".gsub(/^/, " ")
29
- puts "#{deal.posted}".gsub(/^/, " ")
30
- puts ""
31
- end
32
- end
33
- end
27
+ input = gets.strip.to_i
28
+ case input
29
+ when 1
30
+ @deals = @deals = PopularDeals::NewDeals.scrap_slickdeals(BASE_URL)
31
+ puts ""
32
+ puts "---------- Deal list #{input} - #{input+19} ----------"
33
+ puts ""
34
+ when 2
35
+ @deals = @deals = PopularDeals::NewDeals.scrap_slickdeals(PAGE2_URL)
36
+ puts ""
37
+ puts "---------- Deal list #{input} - #{input+19} ----------"
38
+ puts ""
39
+ when 3
40
+ @deals = @deals = PopularDeals::NewDeals.scrap_slickdeals(PAGE3_URL)
41
+ puts ""
42
+ puts "---------- Deal list #{input} - #{input+19} ----------"
43
+ puts ""
44
+ when 4
45
+ @deals = @deals = PopularDeals::NewDeals.scrap_slickdeals(PAGE4_URL)
46
+ puts ""
47
+ puts "---------- Deal list #{input} - #{input+19} ----------"
48
+ puts ""
49
+ when 5
50
+ @deals = @deals = PopularDeals::NewDeals.scrap_slickdeals(PAGE5_URL)
51
+ puts ""
52
+ puts "---------- Deal list #{input} - #{input+19} ----------"
53
+ puts ""
54
+ else
55
+ puts "Don't understand that command".colorize(:color => :white, :background => :red)
56
+ select_list_of_deals
57
+ end
58
+ @deals
59
+ end
60
+
61
+ def list_deals
62
+ @deals.each.with_index(1) do |deal, i|
63
+ if i < 10
64
+ puts "#{i}. #{deal.title}".cyan.bold
65
+ puts "Deal rating: #{deal.deal_rating}.".gsub(/^/, " ")
66
+ puts "Deal value - #{deal.price}".gsub(/^/, " ")
67
+ puts "#{deal.posted}".gsub(/^/, " ")
68
+ puts ""
69
+ elsif i >= 10
70
+ puts "#{i}. #{deal.title}".cyan.bold
71
+ puts "Deal rating: #{deal.deal_rating}.".gsub(/^/, " ")
72
+ puts "Deal value - #{deal.price}".gsub(/^/, " ")
73
+ puts "#{deal.posted}".gsub(/^/, " ")
74
+ puts ""
75
+ end
76
+ end
34
77
  end
35
78
 
36
79
  def menu
@@ -38,38 +81,38 @@ class PopularDeals::CLI
38
81
  while input != "exit"
39
82
 
40
83
  puts ""
41
- puts "Enter the number of deal you would like more info on or type Exit".light_blue.bold
84
+ puts "Enter the number of deal you would like more info on or type Exit.".light_blue.bold
85
+ puts ""
86
+ input = gets.strip.downcase
42
87
  puts ""
43
- input = gets.strip.downcase
44
- puts ""
45
88
 
46
89
  if input.to_i > 0 && input.to_i <= 20
47
90
  puts ""
48
91
  puts "-----------------------------------------------------------------------------------------------------------"
49
92
  puts ""
50
93
  puts "Please see below details of deal no. #{input}".upcase.cyan.bold
51
- disply_deal(input, product_url)
94
+ disply_deal(BASE_URL, input, product_url)
52
95
  #open_deal_in_browser
53
96
  elsif input == "list"
54
97
  list_deals
98
+ elsif input == "select list"
99
+ call
100
+ break
55
101
  elsif input == "exit"
56
102
  goodbye
57
103
  else
58
- puts "Don't understand your command. Type list to see the list or exit".colorize(:color => :white, :background => :red)
104
+ puts "Don't understand your command.".colorize(:color => :white, :background => :red)
105
+ puts "Type 'SELECT LIST' to see available deal lists.".yellow
106
+ puts "Type 'LIST' to see the current deal list.".yellow
107
+ puts "Type 'EXIT' to exit.".yellow
59
108
  puts ""
60
109
  end
61
- end
110
+ end
111
+ #goodbye
62
112
  end
63
113
 
64
- # def open_deal_in_browser
65
- # uri = "http://www.ruby-lang.org"
66
- # Launchy.open( uri ) do |exception|
67
- # puts "Attempted to open #{uri} and failed because #{exception}"
68
- # end
69
- # end
70
-
71
- def disply_deal(input, product_url)
72
- @deal = PopularDeals::NewDeals.deal_page(input, product_url)
114
+ def disply_deal(base_url, input, product_url)
115
+ @deal = PopularDeals::NewDeals.deal_page(BASE_URL, input, product_url)
73
116
  keys = @deal.keys
74
117
  puts ""
75
118
  puts "DEAL:".magenta.bold.gsub(/^/, " ")
@@ -3,19 +3,9 @@ class PopularDeals::NewDeals
3
3
 
4
4
  attr_accessor :title, :url, :deal_rating, :price, :posted, :name, :discription, :purchase, :purchase_link
5
5
 
6
- def self.new_deals
7
- self.scrap_deals
8
- end
9
-
10
- def self.scrap_deals
11
- deals = []
12
- deals << self.scrap_slickdeals
13
- deals
14
- end
15
-
16
- def self.scrap_slickdeals
17
- doc = Nokogiri::HTML(open("https://slickdeals.net/deals/"))
18
-
6
+ def self.scrap_slickdeals(base_url)
7
+ doc = Nokogiri::HTML(open(base_url))
8
+ deals = []
19
9
  all_deals = doc.css("div.dealRow")
20
10
  all_deals.collect do |one_deal|
21
11
  deal = self.new
@@ -28,41 +18,32 @@ class PopularDeals::NewDeals
28
18
  date = one_deal.css("div.dealLinks").first.text.strip
29
19
  new_array = date.split
30
20
  deal.posted = "#{new_array[0]} #{new_array[1]}"
31
- deal
21
+ deals << deal
32
22
  end
23
+ deals
33
24
  end
34
25
 
35
- def self.open_deal_page(input)
26
+ def self.open_deal_page(base_url, input)
36
27
  index = input.to_i - 1
37
- @deals = PopularDeals::NewDeals.new_deals
38
- @deals.each do |info|
39
- d = info[index]
40
- @product_url = "#{d.url}"
41
- end
42
- @product_url
28
+ @deals = PopularDeals::NewDeals.scrap_slickdeals(base_url)
29
+ @product_url = "#{@deals[index].url}"
30
+ @product_url
43
31
  end
44
32
 
45
- def self.deal_page(input, product_url)
46
- self.open_deal_page(input)
33
+ def self.deal_page(base_url, input, product_url)
34
+ self.open_deal_page(base_url, input)
47
35
  deal = {}
48
36
  html = open(@product_url)
49
37
  doc = Nokogiri::HTML(html)
50
38
  data = doc.text.strip
51
39
  deal[:name] = doc.css("h1").text.strip
52
40
  deal[:discription] = doc.css(".textDescription").text.strip
53
- #@purchase_link = ""
54
- if doc.at_css("a#largeBuyNow").nil?
41
+ if doc.at_css("a#largeBuyNow").nil?
55
42
  deal[:purchase] = @product_url
56
43
  else
57
44
  deal[:purchase] = doc.at_css("a#largeBuyNow").attr("href")
58
45
  end
59
- # @purchase_link= doc.at_css("a#largeBuyNow").attr("href")
60
- # if @purchase_link.nil?
61
- # deal[:purchase] = @product_url
62
- # else
63
- # deal[:purchase] = @purchase_link
64
- # end
65
- deal
46
+ deal
66
47
  end
67
48
 
68
49
  end
@@ -1,3 +1,3 @@
1
1
  module PopularDeals
2
- VERSION = "0.2.5"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -10,7 +10,13 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["'hima_chhag@yahoo.com'"]
11
11
 
12
12
  spec.summary = %q{It displays popular deals of the day from https://slickdeals.net/deals/ with popular-deals command.}
13
- spec.description = %q{This CLI App displays a list of the popular deals with deal rating and price. Just use 'popular-deals' command. You can also see a deal details by selecting number of the deal you may be interested in.}
13
+ #spec.description = %q{This CLI gem displays 100 popular deals with deal rating and price from slickdeals.net/deals. Just use 'popular-deals' command. You can also see a deal details by selecting number of the deal you may be interested in.}
14
+ spec.description = <<-EOF
15
+ This CLI gem displays 100 popular deals with ratings and prices from slickdeals.net/deals. Just use 'popular-deals' command.
16
+
17
+ You can also view more details by typing respective deal number.
18
+ EOF
19
+
14
20
  spec.homepage = "https://github.com/HimaChitalia/popular_deals"
15
21
  spec.license = "MIT"
16
22
 
@@ -27,6 +33,7 @@ Gem::Specification.new do |spec|
27
33
 
28
34
  spec.add_dependency "nokogiri"
29
35
  spec.add_dependency "colorize", '~> 0'
36
+ spec.add_dependency "pry"
30
37
 
31
38
 
32
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: popular_deals
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - "'Hima Chitalia'"
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-06 00:00:00.000000000 Z
11
+ date: 2017-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,9 +66,24 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- description: This CLI App displays a list of the popular deals with deal rating and
70
- price. Just use 'popular-deals' command. You can also see a deal details by selecting
71
- number of the deal you may be interested in.
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: |2
84
+ This CLI gem displays 100 popular deals with ratings and prices from slickdeals.net/deals. Just use 'popular-deals' command.
85
+
86
+ You can also view more details by typing respective deal number.
72
87
  email:
73
88
  - "'hima_chhag@yahoo.com'"
74
89
  executables: