news_helper 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: faf42ffcceecbccab203ae93a97ce864264a6c50b2b07693d3e0b83a1b24f515
4
+ data.tar.gz: 3cec5eca87da57c1f4f110cfd1bf119eeaae609766112b93206b8b1e1b1b6a3e
5
+ SHA512:
6
+ metadata.gz: a226e8db05fc633c8146f0736e241f6fcb921715bf3ef14433872acf181160e6cace61cfffdefc92dc9276c5a803544e6c30b831c8f9430fd9ee80f0b827dd39
7
+ data.tar.gz: cb1d23c8b70bceb60b58ae4799c454bc293ddc4a009131254c0b8237707bac25c82a015cf9c76a5768a1656bec66028a479f107b3d2bfdfefb7eabeeeeba5264
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in news_helper.gemspec
4
+ gemspec
@@ -0,0 +1,47 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ news_helper (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.3)
10
+ diff-lcs (1.4.4)
11
+ method_source (1.0.0)
12
+ mini_portile2 (2.4.0)
13
+ nokogiri (1.10.10)
14
+ mini_portile2 (~> 2.4.0)
15
+ open-uri (0.1.0)
16
+ pry (0.13.1)
17
+ coderay (~> 1.1)
18
+ method_source (~> 1.0)
19
+ rake (10.5.0)
20
+ rspec (3.10.0)
21
+ rspec-core (~> 3.10.0)
22
+ rspec-expectations (~> 3.10.0)
23
+ rspec-mocks (~> 3.10.0)
24
+ rspec-core (3.10.0)
25
+ rspec-support (~> 3.10.0)
26
+ rspec-expectations (3.10.0)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.10.0)
29
+ rspec-mocks (3.10.0)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.10.0)
32
+ rspec-support (3.10.0)
33
+
34
+ PLATFORMS
35
+ ruby
36
+
37
+ DEPENDENCIES
38
+ bundler (~> 2.0)
39
+ news_helper!
40
+ nokogiri
41
+ open-uri
42
+ pry
43
+ rake (~> 10.0)
44
+ rspec (~> 3.0)
45
+
46
+ BUNDLED WITH
47
+ 2.0.1
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 'Christian Simon'
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,37 @@
1
+ # NewsHelper
2
+
3
+ Welcome to News_Helper! This gem will help find the latest news for Health, Technology and Politics. It pulls from three different websites, and grabs the first five search results of your chosen topic. All you have to do is follow the instructions given in the CLI, and it will show the title, publication time and URL for your given topic. Enjoy!
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'news_helper'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install news_helper
20
+
21
+ ## Usage
22
+
23
+ Once started with the .start method, news_helper will ask you what topic you are most interested in out of the three given: Tech, Health and Politics. Answering with "1" will give you 15 articles equally distributed from Business Insider, Google and Fox News for a wide range of views and news. The same process will take place when given a "2" or "3" for Health and Politics respectively. After being shown the articles of your choice, you can input "y" for a direct url to the articles, while replying "n" will take you back to the main menu. You can exit whenever you want by typing "exit", where the program will then shut down.
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Christian-Simon1127/news_helper.
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "news_helper"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "news_helper.rb"
5
+
6
+ NewsHelper::CLI.new.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,9 @@
1
+ require "open-uri"
2
+ require "nokogiri"
3
+ require "pry"
4
+
5
+ require_relative "./news_helper/version"
6
+ require_relative "./news_helper/interface"
7
+ require_relative "./news_helper/news"
8
+
9
+
@@ -0,0 +1,46 @@
1
+ class NewsHelper::CLI
2
+
3
+ def start
4
+ display_news
5
+ list_options
6
+ farewell
7
+ end
8
+
9
+ def display_news
10
+ @news = NewsHelper::News.get_news #Nested array containing the news in order of tech, health and politics.
11
+ puts "Hello and welcome to News_Helper! Here you can get up to date news easily, in just one character. If you'd like to see news about tech, enter '1'. If you'd like to see news about health, enter '2'. If you'd like to see news about politics, enter '3'. If you'd like to see your options again, type 'list'. To exit, please just type 'exit'."
12
+ end
13
+
14
+ def list_options
15
+ answer = nil
16
+ while answer != "exit"
17
+ answer = gets.chomp
18
+ if answer == '1'
19
+ @news[0].each_with_index { |article, i|
20
+ puts "\n#{i+1}: #{article.headline}, #{article.publish_date} \n#{article.url}\n"
21
+ }
22
+ elsif answer == '2'
23
+ @news[1].each_with_index { |article, i|
24
+ puts "\n#{i+1}: #{article.headline}, #{article.publish_date} \n#{article.url}\n"
25
+ }
26
+ elsif answer == '3'
27
+ @news[2].each_with_index { |article, i|
28
+ puts "\n#{i+1}: #{article.headline}, #{article.publish_date} \n#{article.url}\n"
29
+ }
30
+ elsif answer == "list"
31
+ display_news
32
+ elsif answer.downcase == "exit"
33
+ puts ""
34
+ answer = "exit"
35
+ else
36
+ puts "Sorry, that isn't a valid command, please re-enter your answer."
37
+ end
38
+ end
39
+ end
40
+
41
+ def farewell
42
+ puts "Thank you for using News_Helper! Come back later when there's more news!"
43
+ end
44
+
45
+
46
+ end
@@ -0,0 +1,84 @@
1
+ class NewsHelper::News
2
+ attr_accessor :headline, :publish_date, :url
3
+
4
+ def self.get_news
5
+ news = [
6
+ self.scrape_tech_sites,
7
+ self.scrape_health_sites,
8
+ self.scrape_political_sites
9
+ ]
10
+ end
11
+
12
+ def self.scrape_tech_sites
13
+ bus = Nokogiri::HTML(URI.open("https://www.businessinsider.com/sai"))
14
+ google = Nokogiri::HTML(URI.open("https://news.google.com/topics/CAAqJggKIiBDQkFTRWdvSUwyMHZNRGRqTVhZU0FtVnVHZ0pWVXlnQVAB?hl=en-US&gl=US&ceid=US%3Aen"))
15
+ fox = Nokogiri::HTML(URI.open("https://www.foxnews.com/tech/"))
16
+ #The below method calls methods designed to scrape business insider, google and fox news
17
+
18
+ sort_news(scrape_bus_ins(bus), scrape_google_news(google), scrape_fox_news(fox))
19
+ end
20
+
21
+ def self.scrape_health_sites
22
+ bus = Nokogiri::HTML(URI.open("https://www.businessinsider.com/healthcare"))
23
+ google = Nokogiri::HTML(URI.open("https://news.google.com/topics/CAAqIQgKIhtDQkFTRGdvSUwyMHZNR3QwTlRFU0FtVnVLQUFQAQ?hl=en-US&gl=US&ceid=US%3Aen"))
24
+ fox = Nokogiri::HTML(URI.open("https://www.foxnews.com/health"))
25
+
26
+ sort_news(scrape_bus_ins(bus), scrape_google_news(google), scrape_fox_news(fox))
27
+ end
28
+
29
+ def self.scrape_political_sites
30
+ bus = Nokogiri::HTML(URI.open("https://www.businessinsider.com/s?q=politics"))
31
+ google = Nokogiri::HTML(URI.open("https://news.google.com/topics/CAAqIQgKIhtDQkFTRGdvSUwyMHZNRFZ4ZERBU0FtVnVLQUFQAQ?hl=en-US&gl=US&ceid=US%3Aen"))
32
+ fox = Nokogiri::HTML(URI.open("https://www.foxnews.com/politics/"))
33
+
34
+ sort_news(scrape_bus_ins(bus), scrape_google_news(google), scrape_fox_news(fox))
35
+ end
36
+
37
+ def self.scrape_bus_ins(bus_page)
38
+ scraped_news = [] #To hold and return the News objects
39
+ bus_page.css(".river-item.featured-post").each {|section|
40
+ article = self.new
41
+ article.headline = section.css("a.tout-title-link").text.strip
42
+ article.publish_date = section.css("span.tout-timestamp").text.split("T")[0]
43
+ article.url = "https://www.businessinsider.com" + section.css("a.tout-title-link").attribute("href").value.strip
44
+ scraped_news << article
45
+ }
46
+ scraped_news
47
+ end
48
+
49
+ def self.scrape_google_news(google_page)
50
+ scraped_news = []
51
+ google_page.css(".xrnccd.F6Welf.R7GTQ.keNKEd.j7vNaf").each {|section|
52
+ article = self.new
53
+ article.headline = section.css("a.DY5T1d").first.text
54
+ article.publish_date = section.css(".WW6dff.uQIVzc.Sksgp").first.text.strip
55
+ article.url = "https://news.google.com" + section.css(".VDXfz").attribute("href").value.strip
56
+ scraped_news << article
57
+ }
58
+ scraped_news
59
+ end
60
+
61
+ def self.scrape_fox_news(fox_page)
62
+ scraped_news = []
63
+ articles = fox_page.css(".content.article-list") #This is to avoid some more off-topic articles at the top of the page
64
+ articles.css("article.article").each {|section|
65
+ article = self.new
66
+ article.headline = section.css(".title").text.strip
67
+ article.publish_date = section.css(".time").text.strip
68
+ article.url = "https://www.foxnews.com" + section.css(".m").css("a").attribute("href").value.strip
69
+ scraped_news << article
70
+ }
71
+ scraped_news
72
+ end
73
+
74
+ def self.sort_news(source_1, source_2, source_3)
75
+ sorted_news = [] #This will be the array of 15 articles, five from each website
76
+ 5.times { |i|
77
+ sorted_news << source_1[i]
78
+ sorted_news << source_2[i]
79
+ sorted_news << source_3[i]
80
+ }
81
+ sorted_news
82
+ end
83
+
84
+ end
@@ -0,0 +1,3 @@
1
+ module NewsHelper
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,43 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ #require "version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "news_helper"
7
+ spec.version = "0.1.0"
8
+ spec.authors = ["'Christian Simon'"]
9
+ spec.email = ["'csimon1127@gmail.com'"]
10
+
11
+ spec.summary = "Welcome to News_Helper! This gem will help find the latest news for Health, Technology and Politics. It pulls from three different websites, and grabs the first five search results of your chosen topic. All you have to do is follow the instructions given in the CLI, and it will show the title, publication time and URL for your given topic. Enjoy!"
12
+ spec.homepage = "https://github.com/Christian-Simon1127/news_helper"
13
+ spec.license = "MIT"
14
+
15
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
16
+ # # to allow pushing to a single host or delete this section to allow pushing to any host.
17
+ # if spec.respond_to?(:metadata)
18
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
19
+
20
+ # spec.metadata["homepage_uri"] = spec.homepage
21
+ # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
22
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
23
+ # else
24
+ # raise "RubyGems 2.0 or newer is required to protect against " \
25
+ # "public gem pushes."
26
+ # end
27
+
28
+ # Specify which files should be added to the gem when it is released.
29
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
31
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
32
+ end
33
+ spec.bindir = "exe"
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ["lib"]
36
+
37
+ spec.add_development_dependency "bundler", "~> 2.0"
38
+ spec.add_development_dependency "rake", "~> 10.0"
39
+ spec.add_development_dependency "rspec", "~> 3.0"
40
+ spec.add_development_dependency "pry"
41
+ spec.add_development_dependency "nokogiri"
42
+ spec.add_development_dependency "open-uri"
43
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: news_helper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - "'Christian Simon'"
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-11-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: open-uri
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - "'csimon1127@gmail.com'"
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - Gemfile
105
+ - Gemfile.lock
106
+ - LICENSE
107
+ - README.md
108
+ - Rakefile
109
+ - bin/console
110
+ - bin/news_helper
111
+ - bin/setup
112
+ - lib/news_helper.rb
113
+ - lib/news_helper/interface.rb
114
+ - lib/news_helper/news.rb
115
+ - lib/news_helper/version.rb
116
+ - news_helper.gemspec
117
+ homepage: https://github.com/Christian-Simon1127/news_helper
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubygems_version: 3.0.3
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Welcome to News_Helper! This gem will help find the latest news for Health,
140
+ Technology and Politics. It pulls from three different websites, and grabs the first
141
+ five search results of your chosen topic. All you have to do is follow the instructions
142
+ given in the CLI, and it will show the title, publication time and URL for your
143
+ given topic. Enjoy!
144
+ test_files: []