breaking-news 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f18f248e9a8867f15c41185aef237fb30f86df68
4
+ data.tar.gz: 77292947d5aa8045cfb4472545844bb4737b785f
5
+ SHA512:
6
+ metadata.gz: 20f358ac6ccd462768301aa87f8eb6bc626d60fefdd5db6d17f9c44587d17f86c74d9648f158ea117982c567d35ba97f4bb748b46303e84c8430f0cd7761701e
7
+ data.tar.gz: 873bde4f65d2007345cc801ed57cb08187fbfc7b5a13e0eebab725d7ff9c9cc8692d0ca01ccee2f22752e04c212caf4a025eb6cb2513db6097fd59aa576fe61f
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.4
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at oats000@hotmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in breaking_news.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 tyleresmith
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.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # BreakingNews
2
+
3
+ Accesses the top news article by region or topic.
4
+
5
+ ## Installation
6
+
7
+ $ gem install breaking_news
8
+
9
+ ## Usage
10
+
11
+ Type in the in command line and follow prompts
12
+
13
+ $ breaking-news
14
+
15
+ ## Development
16
+
17
+ 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.
18
+
19
+ 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).
20
+
21
+ ## Contributing
22
+
23
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/breaking_news. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
24
+
25
+
26
+ ## License
27
+
28
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
29
+
data/Rakefile ADDED
@@ -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
data/bin/breaking-news ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'breaking_news'
4
+ BreakingNews::CLI.new.call
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "breaking_news"
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
data/bin/setup ADDED
@@ -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,38 @@
1
+ --A CLI for pulling the top article in by region
2
+
3
+ Beep-Beep Beep Beep
4
+ Breaking News! This just in!
5
+
6
+ Select your region or topic:
7
+
8
+ 1. World ##http://www.bbc.com/news/world
9
+ 2. North America ##http://www.bbc.com/news/world/us_and_canada
10
+ 3. Asia ##http://www.bbc.com/news/world/asia
11
+ 4. Africa ##http://www.bbc.com/news/world/africa
12
+ 5. Europe ##http://www.bbc.com/news/world/europe
13
+ 6. Latin America ##http://www.bbc.com/news/world/latin_america
14
+ 7. Middle East ##http://www.bbc.com/news/world/middle_east
15
+ 8. Australia ##http://www.bbc.com/news/world/australia
16
+ 9. UK ##http://www.bbc.com/news/uk
17
+ 10. Business ##http://www.bbc.com/news/business
18
+ 11. Tech ##http://www.bbc.com/news/technology
19
+ 12. Science ##http://www.bbc.com/news/science_and_environment
20
+ 13. Entertainment & Arts ##http://www.bbc.com/news/entertainment_and_arts
21
+ 14. Health ##http://www.bbc.com/news/health
22
+
23
+
24
+ 1
25
+
26
+
27
+ ---------World----------
28
+
29
+ Posted : 4 hours ago
30
+
31
+ US states vote in crucial primaries
32
+
33
+ Five US states are holding primary elections for November's presidential poll, in a crucial round that could give Democratic and Republican front-runners a chance to cement their leads.
34
+
35
+ Select your region or topic:
36
+
37
+ Enter list to see options again.
38
+ Enter exit to end the program
@@ -0,0 +1,27 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'breaking_news/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "breaking-news"
8
+ spec.version = BreakingNews::VERSION
9
+ spec.date = '2016-03-17'
10
+ spec.summary = "Top articles per region or topic."
11
+ spec.description = "Provides the top article from BBC based on region or topic"
12
+ spec.authors = ["tyleresmith"]
13
+ spec.email = ["oats000@hotmail.com"]
14
+ spec.files = `git ls-files`.split($\)
15
+ spec.require_paths = ["lib", "lib/breaking_news"]
16
+ spec.homepage = "http://rubygems.org/gems/breaking-news"
17
+ spec.license = "MIT"
18
+ spec.executables = ["breaking-news"]
19
+
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.11"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+ spec.add_development_dependency "nokogiri", ">= 0"
25
+ spec.add_development_dependency "pry", ">= 0"
26
+ end
27
+
@@ -0,0 +1,12 @@
1
+ require 'nokogiri'
2
+ require 'pry'
3
+ require 'open-uri'
4
+
5
+
6
+ require_relative "breaking_news/version"
7
+ require_relative 'breaking_news/cli'
8
+ require_relative 'breaking_news/scraper'
9
+ require_relative 'breaking_news/article'
10
+
11
+ module BreakingNews
12
+ end
@@ -0,0 +1,14 @@
1
+ class BreakingNews::Article
2
+ attr_accessor :headline, :p5, :date, :p1, :p2, :p3, :p4
3
+
4
+ def initialize(hash)
5
+ @headline = hash[:headline]
6
+ @date = hash[:date]
7
+ @p1 = hash[:p1]
8
+ @p2 = hash[:p2]
9
+ @p3 = hash[:p3]
10
+ @p4 = hash[:p4]
11
+ @p5 = hash[:p5]
12
+ end
13
+
14
+ end
@@ -0,0 +1,121 @@
1
+ class BreakingNews::CLI
2
+
3
+ def call
4
+ intro
5
+ list_choices
6
+ menu
7
+ goodbye
8
+ end
9
+
10
+ def list_choices
11
+ puts "1. World" ##http://www.bbc.com/news/world
12
+ puts "2. North America" ##http://www.bbc.com/news/world/us_and_canada
13
+ puts "3. Asia" ##http://www.bbc.com/news/world/asia
14
+ puts "4. Africa" ##http://www.bbc.com/news/world/africa
15
+ puts "5. Europe" ##http://www.bbc.com/news/world/europe
16
+ puts "6. Latin America" ##http://www.bbc.com/news/world/latin_america
17
+ puts "7. Middle East" ##http://www.bbc.com/news/world/middle_east
18
+ puts '8. Australia' ##http://www.bbc.com/news/world/australia
19
+ puts '9. UK' ##http://www.bbc.com/news/uk
20
+ puts '10. Business' ##http://www.bbc.com/news/business
21
+ puts '11. Tech' ##http://www.bbc.com/news/technology
22
+ puts '12. Science' ##http://www.bbc.com/news/science_and_environment
23
+ puts '13. Entertainment & Arts' ##http://www.bbc.com/news/entertainment_and_arts
24
+ puts '14. Health'
25
+ end
26
+
27
+ def intro
28
+ puts "********Beep-Beep Beep Beep!********"
29
+ puts "****Breaking News! This just in!****"
30
+ puts ""
31
+ end
32
+
33
+ def menu
34
+ puts ""
35
+ puts "Select your region or topic: (1-14)"
36
+ puts ""
37
+ puts "Enter list to see options again."
38
+ puts "Enter exit to end the program."
39
+ input = gets.strip
40
+
41
+ case input
42
+ when "1"
43
+ puts "------------World------------"
44
+ display_article("http://www.bbc.com/news/world")
45
+ when "2"
46
+ puts "------------North America------------"
47
+ display_article("http://www.bbc.com/news/world/us_and_canada")
48
+ when "3"
49
+ puts "------------Asia------------"
50
+ display_article("http://www.bbc.com/news/world/asia")
51
+ when "4"
52
+ puts "------------Africa------------"
53
+ display_article("http://www.bbc.com/news/world/africa")
54
+ when "5"
55
+ puts "------------Europe------------"
56
+ display_article("http://www.bbc.com/news/world/europe")
57
+ when "6"
58
+ puts "------------Latin America------------"
59
+ display_article("http://www.bbc.com/news/world/latin_america")
60
+ when "7"
61
+ puts "------------Middle East------------"
62
+ display_article("http://www.bbc.com/news/world/middle_east")
63
+ when "8"
64
+ puts "------------Australia------------"
65
+ display_article("http://www.bbc.com/news/world/australia")
66
+ when "9"
67
+ puts "------------UK------------"
68
+ display_article("http://www.bbc.com/news/uk")
69
+ when "10"
70
+ puts "------------Business------------"
71
+ display_article("http://www.bbc.com/news/business")
72
+ when "11"
73
+ puts "------------Technology------------"
74
+ display_article("http://www.bbc.com/news/technology")
75
+ when "12"
76
+ puts "------------Science------------"
77
+ display_article("http://www.bbc.com/news/science_and_environment")
78
+ when "13"
79
+ puts "------------Entertainment & Arts------------"
80
+ display_article("http://www.bbc.com/news/entertainment_and_arts")
81
+ when "14"
82
+ puts "------------Health------------"
83
+ display_article("http://www.bbc.com/news/health")
84
+ when "exit"
85
+ nil
86
+ when "list"
87
+ list_choices
88
+ menu
89
+ else
90
+ menu
91
+ end
92
+ end
93
+
94
+ def goodbye
95
+ puts "Check back later for new articles!"
96
+ end
97
+
98
+ def display_article(url)
99
+ page = BreakingNews::Scraper.new.scrape_root(url)
100
+ article = BreakingNews::Article.new(page)
101
+ #binding.pry
102
+ puts "Date: #{article.date}"
103
+ puts ""
104
+ puts "**#{article.headline}**"
105
+ puts ""
106
+ puts ""
107
+ puts article.p1
108
+ puts ""
109
+ puts article.p2
110
+ puts ""
111
+ puts article.p3
112
+ puts ""
113
+ puts article.p4
114
+ puts ""
115
+ puts article.p5
116
+ puts ""
117
+ puts "------------------------------"
118
+ menu
119
+ end
120
+
121
+ end
@@ -0,0 +1,25 @@
1
+
2
+
3
+ class BreakingNews::Scraper
4
+
5
+ def scrape_root(root_url)
6
+
7
+ root_page = Nokogiri::HTML(open(root_url))
8
+
9
+ target_url = "http://www.bbc.com/#{root_page.css("div.buzzard-item a").attribute("href").value}"
10
+ target_page = Nokogiri::HTML(open(target_url))
11
+ h = {}
12
+ h[:headline] = target_page.css("h1.story-body__h1").text
13
+ h[:date] = target_page.css("li.mini-info-list__item div").text
14
+ h[:p1] = target_page.css("div.story-body__inner p:nth-child(1)").text
15
+ h[:p2] = target_page.css("div.story-body__inner p:nth-child(2)").text
16
+ h[:p3] = target_page.css("div.story-body__inner p:nth-child(3)").text
17
+ h[:p4] = target_page.css("div.story-body__inner p:nth-child(4)").text
18
+ h[:p5] = target_page.css("div.story-body__inner p:nth-child(5)").text
19
+ h
20
+ #binding.pry
21
+ end
22
+
23
+ end
24
+
25
+
@@ -0,0 +1,3 @@
1
+ module BreakingNews
2
+ VERSION = "0.1.2"
3
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe BreakingNews do
4
+ it 'has a version number' do
5
+ expect(BreakingNews::VERSION).not_to be nil
6
+ end
7
+
8
+ it 'does something useful' do
9
+ expect(false).to eq(true)
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'breaking_news'
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: breaking-news
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - tyleresmith
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-17 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: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
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: nokogiri
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: pry
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
+ description: Provides the top article from BBC based on region or topic
84
+ email:
85
+ - oats000@hotmail.com
86
+ executables:
87
+ - breaking-news
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - CODE_OF_CONDUCT.md
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/breaking-news
100
+ - bin/console
101
+ - bin/setup
102
+ - breaking-news.mdown
103
+ - breaking_news.gemspec
104
+ - lib/breaking_news.rb
105
+ - lib/breaking_news/article.rb
106
+ - lib/breaking_news/cli.rb
107
+ - lib/breaking_news/scraper.rb
108
+ - lib/breaking_news/version.rb
109
+ - spec/breaking_news_spec.rb
110
+ - spec/spec_helper.rb
111
+ homepage: http://rubygems.org/gems/breaking-news
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ - lib/breaking_news
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.4.5.1
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: Top articles per region or topic.
136
+ test_files: []