covid_19_updates 0.1.1 → 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: 2ad7e8b17a3d5c38143a605e8eb00435d36d05fedecc226caef34059fe3a8de5
4
- data.tar.gz: 94b65be7797916ca34910ccb711d2d0f203c1e3010b6b786a01a800715ec2c23
3
+ metadata.gz: 2bc6389206b8ead069229e95ee7e6696336962cdfe3747d6106ffc42370a72ee
4
+ data.tar.gz: 709fc65b06d47d24d2ce7f1f11482426c29ddaa9d8e8bb7823a142615e5daa38
5
5
  SHA512:
6
- metadata.gz: 1848ffadea7048b82ce790def43f951e5db4187c8c420d83b4b8980d73436081efe634901282d4ae4420f386cedf86ff6c484d7c54e8553e8870cce10a27c03a
7
- data.tar.gz: f42f6cca5388d8c3208989e65e14df85c11a1a413eccfc0c0c1999f8ff088afe73db2d54c77605e93958f8143463ff55ea9fd1cf94be1d2ba0565e11e2a39738
6
+ metadata.gz: 8f2ccd963f760eb77a18d8e6162ea55656ca27cc5253d252ff8e6c1ce4b2b6979a076ddff48b80a6fc5597d23bd0be2f71cf829473df9d62e3418e83e051ec8a
7
+ data.tar.gz: 921c4cad272d152cb6ace59d44092eea6a3c4049180d158c9d2dc1ee8fef1e4956e561b1c28421e3ff1799d462c032b427bb9338190b7be280518fdfbf9154cd
data/.DS_Store CHANGED
Binary file
data/Gemfile CHANGED
@@ -5,6 +5,6 @@ source 'https://rubygems.org'
5
5
  # Specify your gem's dependencies in covid_19_updates.gemspec
6
6
  gemspec
7
7
 
8
- gem 'covid_19_updates'
8
+ # gem 'covid_19_updates'
9
9
  gem 'rake', '~> 12.0'
10
10
  gem 'rspec', '~> 3.0'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- covid_19_updates (0.1.0)
4
+ covid_19_updates (0.1.1)
5
5
  colorize
6
6
  nokogiri
7
7
  thor (>= 1.0.1)
@@ -39,4 +39,4 @@ DEPENDENCIES
39
39
  rspec (~> 3.0)
40
40
 
41
41
  BUNDLED WITH
42
- 1.17.2
42
+ 2.1.4
data/README.md CHANGED
@@ -21,7 +21,7 @@ Or install it yourself as:
21
21
  $ gem install covid_19_updates
22
22
 
23
23
  ## Usage
24
- When gem has been downloaded, run 'cov list' to start program. All other instructions will be placed on screen for user to respond to. Thank you and be safe out there!
24
+ When gem has been downloaded, run 'cov start' to start program. All other instructions will be placed on screen for user to respond to. Thank you and be safe out there!
25
25
 
26
26
 
27
27
  ## Development
data/lib/.DS_Store CHANGED
Binary file
@@ -4,6 +4,8 @@ require 'thor'
4
4
  require 'nokogiri'
5
5
  require 'open-uri'
6
6
  require 'colorize'
7
+ require_relative 'headlines'
8
+ require_relative 'scraper'
7
9
 
8
10
  module Covid19Updates
9
11
  class CLI < Thor
@@ -13,66 +15,31 @@ module Covid19Updates
13
15
 
14
16
  desc 'start', 'Prints out greeting and basic commands'
15
17
  def start
16
- list
18
+ list
17
19
  end
18
20
 
19
21
  desc 'start', 'Prints out greeting and basic commands'
20
22
  def list
21
23
  list_new_networks
22
-
23
- news_net = ask('Enter number assigned to news network')
24
-
25
- case news_net
26
- when '1'
27
- cnbc_headline
28
- when '2'
29
- fox_headline
30
- when '3'
31
- stat_headline
32
- else
33
- puts 'No news source by that number.'.red.bold
34
- puts ""
35
- puts ""
36
- call
37
- end
24
+ enter_news_network_number
38
25
  end
39
26
 
40
27
  private
41
28
 
42
29
  def cnbc_headline
43
- doc = Nokogiri::HTML(URI.open('https://www.cnbc.com/coronavirus/'))
44
-
45
- items = doc.css('div.Card-titleContainer')
46
-
47
- array = []
48
- items.each do |item|
49
- array << { title: item.text, link: item.children.attribute('href').value }
50
- end
30
+ array = Headlines.new('https://www.cnbc.com/coronavirus/', 'div.Card-titleContainer').show_headlines
51
31
 
52
- array.each_with_index do |news, index|
53
- puts "#{index.succ}: #{news[:title]}"
54
- end
32
+ puts_headlines(array)
55
33
 
56
- puts
57
- pick = ask('Please pick a number to view an update: ')
58
- puts
34
+ pick
59
35
 
60
- print Nokogiri::HTML(URI.open((array[pick.to_i - 1][:link]).to_s)).css('div.group').text.gsub('Â', '').light_blue
61
- puts
36
+ Scraper.fetch(array, @pick, 'cnbc')
62
37
 
63
- continue
38
+ continue
64
39
  end
65
40
 
66
41
  def fox_headline
67
- doc = Nokogiri::HTML(URI.open('https://www.foxnews.com/category/health/infectious-disease/coronavirus'))
68
- items = doc.css('header.info-header')
69
-
70
- array = []
71
- items.each do |item|
72
- if item.at_css('h4.title a')&.text != nil
73
- array << { title: item.at_css('h4.title a')&.text, link: item.at_css('h4.title a')&.attribute('href')&.value }
74
- end
75
- end
42
+ array = Headlines.new('https://www.foxnews.com/category/health/infectious-disease/coronavirus', 'header.info-header').show_headlines
76
43
 
77
44
  final = array.map! do |item|
78
45
  item unless item[:link].start_with?('https')
@@ -81,72 +48,69 @@ module Covid19Updates
81
48
  end
82
49
 
83
50
  final.each_with_index do |news, index|
84
- puts "#{index.succ}: #{news[:title]}"
51
+ puts "#{index.succ}: #{news[:title]}".red
85
52
  end
86
53
 
87
- puts
88
- pick = ask('Please pick a number to view an update: ')
89
- puts
54
+ pick
90
55
 
91
-
92
- # n.css('p')[rand(3..(n.css('p').count))].text (n.css('p').count)
93
- n = final[pick.to_i - 1][:link].to_s
56
+ n = final[@pick.to_i - 1][:link].to_s
94
57
  node = Nokogiri::HTML(URI.open(n)).css('p')
95
58
 
96
- print node[rand(3..(node.count-4))].text.light_blue
59
+ print node[rand(3..(node.count - 2))].text.light_blue
97
60
  puts
98
61
 
99
- continue
62
+ continue
100
63
  end
101
64
 
102
65
  def stat_headline
103
- doc = Nokogiri::HTML(URI.open('https://www.statnews.com/tag/coronavirus/'))
104
- items = doc.css('a.post-title-link')
66
+ array = Headlines.new('https://www.statnews.com/tag/coronavirus/', 'a.topic-block__preview-title').show_headlines
105
67
 
106
- # binding.irb
107
-
108
- array = []
109
- items.each do |item|
110
- array << { title: item.text, link: item.attribute('href').value }
111
- end
112
-
113
- array.each_with_index do |news, index|
114
- puts "#{index.succ}: #{news[:title]}"
115
- end
68
+ puts_headlines(array)
116
69
 
117
- puts
118
- pick = ask('Please pick a number to view an update: ')
119
- puts
70
+ pick
120
71
 
121
- print Nokogiri::HTML(URI.open((array[pick.to_i - 1][:link]).to_s)).css('a.post-title-link').text.light_blue
122
- puts
72
+ Scraper.fetch(array, @pick, 'stat')
123
73
 
124
74
  continue
125
75
  end
126
76
 
127
77
  def continue
128
- puts ""
129
- puts ""
130
- message = ask('Would you like to continue reading updates? (y/n)')
78
+ puts ''
79
+ puts ''
80
+ message = ask('Would you like to continue reading updates? (y/n)')
131
81
 
132
- if message == "y"
82
+ if message == 'y'
133
83
  call
134
84
  else
135
- puts "Thank you and be safe out there!".light_blue
85
+ puts 'Thank you and be safe out there!'.light_blue
136
86
  end
137
87
  end
138
88
 
139
-
140
89
  def call
141
90
  greeting = <<~DOC
142
-
143
91
  1. CNBC
144
92
  2. FOX NEWS
145
93
  3. STAT NEWS
146
-
147
94
  Enter the number of news website you would like to see updates from.\n Please type cov list to see options or exit to leave.
148
- DOC
95
+ DOC
149
96
  puts greeting.green.bold
97
+
98
+ enter_news_network_number
99
+ end
100
+
101
+ def list_new_networks
102
+ greeting = <<~DOC
103
+ Welcome to Covid-19 Updates!
104
+ View the top headlines from the following sites:
105
+ 1. CNBC
106
+ 2. FOX NEWS
107
+ 3. STAT NEWS
108
+ Enter the number of news website you would like to see updates from.\nPlease type list to see options or exit to leave.
109
+ DOC
110
+ puts greeting.cyan.bold
111
+ end
112
+
113
+ def enter_news_network_number
150
114
  news_net = ask('Enter number assigned to news network')
151
115
 
152
116
  case news_net
@@ -158,25 +122,23 @@ module Covid19Updates
158
122
  stat_headline
159
123
  else
160
124
  puts 'No news source by that number.'.red.bold
161
- puts ""
162
- puts ""
125
+ puts ''
126
+ puts ''
127
+
163
128
  call
164
129
  end
165
130
  end
166
131
 
132
+ def pick
133
+ puts
134
+ @pick = ask('Please pick a number to view an update: ')
135
+ puts
136
+ end
167
137
 
168
- def list_new_networks
169
- greeting = <<~DOC
170
- Welcome to Covid-19 Updates!
171
- View the top headlines from the following sites:
172
-
173
- 1. CNBC
174
- 2. FOX NEWS
175
- 3. STAT NEWS
176
-
177
- Enter the number of news website you would like to see updates from.\n Please type list to see options or exit to leave.
178
- DOC
179
- puts greeting.cyan.bold
138
+ def puts_headlines(array)
139
+ array.each_with_index do |news, index|
140
+ puts "#{index.succ}: #{news[:title]}"
141
+ end
180
142
  end
181
143
  end
182
144
  end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Headlines
4
+ attr_reader :url, :css_class
5
+
6
+ def initialize(url, css_class)
7
+ @url = url
8
+ @css_class = css_class
9
+ end
10
+
11
+ def show_headlines
12
+ doc = Nokogiri::HTML(URI.open(url))
13
+ items = doc.css(css_class)
14
+
15
+ array = []
16
+
17
+ if url.include?('foxnews')
18
+ items.each do |item|
19
+ if item.at_css('h4.title a')&.text != nil
20
+ array << { title: item.at_css('h4.title a')&.text, link: item.at_css('h4.title a')&.attribute('href')&.value }
21
+ end
22
+ end
23
+ else
24
+ items.each do |item|
25
+ array << if url.include?('cnbc')
26
+ { title: item.text.strip.red, link: item.children.attribute('href').value }
27
+ else
28
+ { title: item.text.strip.red, link: item.attribute('href').value }
29
+ end
30
+ end
31
+ end
32
+
33
+ array
34
+ end
35
+ end
@@ -0,0 +1,12 @@
1
+ class Scraper
2
+ def self.fetch(array, pick, network)
3
+ case network
4
+ when 'cnbc'
5
+ print Nokogiri::HTML(URI.open((array[pick.to_i - 1][:link]).to_s)).css('div.group').text.gsub('Â', '').light_blue
6
+ puts
7
+ when 'stat'
8
+ print Nokogiri::HTML(URI.open((array[pick.to_i - 1][:link]).to_s)).css('a.post-title-link').text.light_blue
9
+ puts
10
+ end
11
+ end
12
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Covid19Updates
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: covid_19_updates
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jack Madden
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-27 00:00:00.000000000 Z
11
+ date: 2020-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -78,6 +78,8 @@ files:
78
78
  - lib/.DS_Store
79
79
  - lib/covid_19_updates.rb
80
80
  - lib/covid_19_updates/cli.rb
81
+ - lib/covid_19_updates/headlines.rb
82
+ - lib/covid_19_updates/scraper.rb
81
83
  - lib/covid_19_updates/version.rb
82
84
  homepage: https://rubygems.org/
83
85
  licenses: []
@@ -101,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
103
  - !ruby/object:Gem::Version
102
104
  version: '0'
103
105
  requirements: []
104
- rubygems_version: 3.0.3
106
+ rubygems_version: 3.1.2
105
107
  signing_key:
106
108
  specification_version: 4
107
109
  summary: Find out the latest on the Covd-19 Pandemic.