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 +4 -4
- data/.DS_Store +0 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +2 -2
- data/README.md +1 -1
- data/lib/.DS_Store +0 -0
- data/lib/covid_19_updates/cli.rb +54 -92
- data/lib/covid_19_updates/headlines.rb +35 -0
- data/lib/covid_19_updates/scraper.rb +12 -0
- data/lib/covid_19_updates/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2bc6389206b8ead069229e95ee7e6696336962cdfe3747d6106ffc42370a72ee
|
|
4
|
+
data.tar.gz: 709fc65b06d47d24d2ce7f1f11482426c29ddaa9d8e8bb7823a142615e5daa38
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8f2ccd963f760eb77a18d8e6162ea55656ca27cc5253d252ff8e6c1ce4b2b6979a076ddff48b80a6fc5597d23bd0be2f71cf829473df9d62e3418e83e051ec8a
|
|
7
|
+
data.tar.gz: 921c4cad272d152cb6ace59d44092eea6a3c4049180d158c9d2dc1ee8fef1e4956e561b1c28421e3ff1799d462c032b427bb9338190b7be280518fdfbf9154cd
|
data/.DS_Store
CHANGED
|
Binary file
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
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
|
|
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
|
data/lib/covid_19_updates/cli.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
|
53
|
-
puts "#{index.succ}: #{news[:title]}"
|
|
54
|
-
end
|
|
32
|
+
puts_headlines(array)
|
|
55
33
|
|
|
56
|
-
|
|
57
|
-
pick = ask('Please pick a number to view an update: ')
|
|
58
|
-
puts
|
|
34
|
+
pick
|
|
59
35
|
|
|
60
|
-
|
|
61
|
-
puts
|
|
36
|
+
Scraper.fetch(array, @pick, 'cnbc')
|
|
62
37
|
|
|
63
|
-
|
|
38
|
+
continue
|
|
64
39
|
end
|
|
65
40
|
|
|
66
41
|
def fox_headline
|
|
67
|
-
|
|
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
|
-
|
|
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-
|
|
59
|
+
print node[rand(3..(node.count - 2))].text.light_blue
|
|
97
60
|
puts
|
|
98
61
|
|
|
99
|
-
|
|
62
|
+
continue
|
|
100
63
|
end
|
|
101
64
|
|
|
102
65
|
def stat_headline
|
|
103
|
-
|
|
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
|
-
|
|
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
|
-
|
|
118
|
-
pick = ask('Please pick a number to view an update: ')
|
|
119
|
-
puts
|
|
70
|
+
pick
|
|
120
71
|
|
|
121
|
-
|
|
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 ==
|
|
82
|
+
if message == 'y'
|
|
133
83
|
call
|
|
134
84
|
else
|
|
135
|
-
puts
|
|
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
|
-
|
|
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
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
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.
|
|
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-
|
|
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.
|
|
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.
|