sport_headlines 0.1.0

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: 72dad286df2f6d0b59bd5748e921c97fc578f109
4
+ data.tar.gz: b32b3d3d95b27ea4aa1ff639dd58e3f24099605f
5
+ SHA512:
6
+ metadata.gz: 2b12256526bcc632458d6ceaa68af3b4141ffe2f3363c7bfa67e48967484ab4d23fc9963b1cfe2335edb26feb4ff4a54adac32c863ec24ad2416335e3607e015
7
+ data.tar.gz: 6a3b96c0f0621f9788a7a8d57b40d0e9ecc09e456e3b6a115311da1fe23e5c7fe06f938e1d0bd524cf40dce6b1cf1628c4a0de34f91547a75f4ef3a463a678f9
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.3
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 cernanb@gmail.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 sport_headlines.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 cernanb
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,38 @@
1
+ # SportHeadlines
2
+
3
+ Welcome to my Sport Headlines Aggregator gem! This gem will scrape the top headlines for 4 separate sports websites and you will be able to choose the site and the article you would like to view the content for. I built this gem as a project for the Flatiron School's Learn Verified Full Stack Web Development online program. I hope you enjoy it!
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'sport_headlines'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install sport_headlines
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
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/[USERNAME]/sport_headlines. 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.
34
+
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
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/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sport_headlines"
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,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sport_headlines"
5
+
6
+ SportHeadlines::CLI.new.call
@@ -0,0 +1,9 @@
1
+ class SportHeadlines::Article
2
+ attr_accessor :title, :content, :article_url, :site
3
+
4
+ def print_content
5
+ puts self.content
6
+ puts ""
7
+ end
8
+
9
+ end
@@ -0,0 +1,43 @@
1
+ class SportHeadlines::CLI
2
+ def call
3
+ puts "Welcome to the Sports Headlines Aggregator."
4
+ puts ""
5
+ SportHeadlines::Site.create_sites_from_hash
6
+ start
7
+ end
8
+
9
+ def start
10
+ # sites = SportHeadlines::Site.all
11
+ scraper = SportHeadlines::Scraper
12
+ puts ""
13
+ input = nil
14
+ while input != 'exit'
15
+ puts "Please select a site - by number you would like to view the top headlines from. Enter exit to end the program"
16
+ puts ""
17
+ list_sites
18
+ puts ""
19
+ input = gets.strip
20
+ if input.to_i.between?(1,sites.size)
21
+ site = SportHeadlines::Site.find(input)
22
+ site.scrape_headlines!
23
+ # scraper.scrape_site_headlines(sites[input.to_i-1])
24
+
25
+ puts "Select an article to read its content."
26
+ puts ""
27
+ site.list_articles
28
+ article_input = gets.strip
29
+ article = site.scrape_article(article_input) # preps the article, and returns the instance of the article
30
+ # scraper.scrape_article(sites[input.to_i-1].articles[article_input.to_i - 1])
31
+ article.print_content
32
+
33
+ # sites[input.to_i-1].articles[article_input.to_i - 1].print_content
34
+ end
35
+ end
36
+ end
37
+
38
+ def list_sites
39
+ SportHeadlines::Site.all.each_with_index do |site, index|
40
+ puts "#{index +1}. #{site.site_name}"
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,55 @@
1
+ module SportHeadlines::Scraper
2
+
3
+ def self.scrape_site_headlines(site)
4
+ binding.pry
5
+ doc = Nokogiri::HTML(open(site.site_url))
6
+ site.clear_articles
7
+ if site.site_name == "ESPN"
8
+ doc.search(".headlines li").each do |headline|
9
+ new_article ||= SportHeadlines::Article.new
10
+ new_article.title ||= headline.search("a").text
11
+ new_article.article_url ||= site.site_url + headline.search("a").attribute("href").value
12
+
13
+ # site.add_article(new_article)
14
+ new_article.site = site # has two jobs, first, association the site with the article, then inform the site of the new article
15
+ end
16
+ elsif site.site_name == "Bleacher Report"
17
+ doc.search(".headlineArticles li").each do |headline|
18
+ new_article = SportHeadlines::Article.new
19
+ new_article.title = headline.search("span.title").text
20
+ new_article.article_url = headline.search("a.title").attribute("href").value
21
+ site.add_article(new_article)
22
+ new_article.site = site
23
+ end
24
+ else
25
+ doc.search("#top-headlines li").each do |headline|
26
+ new_article = SportHeadlines::Article.new
27
+ new_article.title = headline.text
28
+ new_article.article_url = headline.search("a").attribute("href").value
29
+ site.add_article(new_article)
30
+ new_article.site = site
31
+ end
32
+ end
33
+ end
34
+
35
+ def self.scrape_article(article)
36
+ doc = Nokogiri::HTML(open(article.article_url))
37
+ p_text = ""
38
+
39
+ if article.site.site_name == "ESPN"
40
+ doc.search(".article-body p").each do |p|
41
+ p_text += " " + p.text + "\n\n"
42
+ end
43
+ elsif article.site.site_name == "Bleacher Report"
44
+ doc.search(".article_body p").each do |p|
45
+ p_text += " " + p.text + "\n"
46
+ end
47
+ elsif article.site.site_name == "Pro Football Talk"
48
+ doc.search(".post-body p").each do |p|
49
+ p_text += " " + p.text + "\n\n"
50
+ end
51
+ end
52
+
53
+ article.content = p_text
54
+ end
55
+ end
@@ -0,0 +1,64 @@
1
+ class SportHeadlines::Site
2
+ attr_accessor :site_name, :site_url, :articles
3
+
4
+ SITES = {
5
+ "ESPN" => "http://espn.go.com/",
6
+ "Bleacher Report" => "http://bleacherreport.com/",
7
+ "Pro Football Talk" => "http://profootballtalk.nbcsports.com/"
8
+ }
9
+ #
10
+ @@all = []
11
+
12
+ def initialize(site_name, site_url)
13
+ @site_name = site_name
14
+ @site_url = site_url
15
+ @articles = []
16
+ @@all << self
17
+ end
18
+
19
+ def self.all
20
+ @@all
21
+ end
22
+
23
+ def clear_articles
24
+ self.articles.clear
25
+ end
26
+
27
+ def self.create_sites_from_hash
28
+ SITES.each do |site, url|
29
+ self.new(site, url)
30
+ end
31
+ end
32
+
33
+ def add_article(article)
34
+ # self is the site, article is the article
35
+ self.articles << article
36
+ article.site = self # reciprocal relationship - when we add ana rticle to a site, we also inform the article of it's relationship to this site
37
+ end
38
+
39
+ def list_articles
40
+ self.articles.each_with_index do |article, index|
41
+ puts "#{index + 1}. #{article.title}"
42
+ end
43
+ end
44
+
45
+ def self.find(input)
46
+ self.all[input.to_i-1]
47
+ end
48
+
49
+ def scrape_headlines!
50
+ SportHeadlines::Scraper.scrape_site_headlines(self)
51
+ end
52
+
53
+ def find_article(input)
54
+ self.articles[input.to_i - 1]
55
+ end
56
+
57
+ def scrape_article(input)
58
+ # we want this method to both scrape the article and return it.
59
+ article = self.find_article(input)
60
+ SportHeadlines::Scraper.scrape_article(article)
61
+ article
62
+ end
63
+
64
+ end
@@ -0,0 +1,3 @@
1
+ module SportHeadlines
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,15 @@
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+ require 'pry'
4
+
5
+ require 'sport_headlines/cli'
6
+
7
+ require "sport_headlines/version"
8
+ require "sport_headlines/article"
9
+ require "sport_headlines/site"
10
+ require "sport_headlines/cli"
11
+ require "sport_headlines/scraper"
12
+
13
+ module SportHeadlines
14
+
15
+ end
data/notes.md ADDED
@@ -0,0 +1,38 @@
1
+ #top sports headlines scraper
2
+ #scrapes top headlines from espn, sportsillustrated, bleacher report, pro football talk
3
+
4
+ How to Build a CLI Gem
5
+
6
+ 1. Plan your gem, imagine your interface
7
+ 2. Start with the project structure
8
+ 3. Start with the entry point - the file run
9
+ 4. Force that to build the CLI interface
10
+ 5. Stub out the interface
11
+ 6. start making things real
12
+ 7. discover objects
13
+ 8. program
14
+
15
+
16
+ "Welcome to the Sports Headlines Aggregator."
17
+
18
+ "Please select a site - by number you would like to view the top headlines from..."
19
+
20
+ 1. ESPN
21
+ 2. Sports Illustrated
22
+ 3. Bleacher Report
23
+ 4. Pro Football Talk
24
+
25
+ => 1. ESPN => list_articles[1-1 = 0]
26
+
27
+ 1. Article 1
28
+ 2. Article 2
29
+ 2. Article 3
30
+ 2. Article 4
31
+
32
+
33
+
34
+ # doc = Nokogiri::HTML(open("http://espn.go.com/")) =>
35
+ # doc = Nokogiri::HTML(open("http://bleacherreport.com/"))
36
+ # doc = Nokogiri::HTML(open("http://www.si.com/"))
37
+ # doc = Nokogiri::HTML(open("http://profootballtalk.nbcsports.com/"))
38
+ # doc.search("div.headlines li").size => returns each headline li in the top headlines
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sport_headlines/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sport_headlines"
8
+ spec.version = SportHeadlines::VERSION
9
+ spec.authors = ["cernanb"]
10
+ spec.email = ["cernanb@gmail.com"]
11
+
12
+ spec.summary = %q{A gem to collate top sport headlines.}
13
+ spec.description = %q{This gem will scrape the current top headlines of popular sport sites.}
14
+ spec.homepage = "https://github.com/cernanb/sport-headlines-cli-gem"
15
+ spec.license = "MIT"
16
+
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ # spec.bindir = "exe"
20
+ spec.executables = ["sport_headlines"]
21
+ spec.require_paths = ["lib", "lib/sport_headlines"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.11"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency 'nokogiri'
27
+ spec.add_development_dependency "pry"
28
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sport_headlines
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - cernanb
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-22 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: This gem will scrape the current top headlines of popular sport sites.
84
+ email:
85
+ - cernanb@gmail.com
86
+ executables:
87
+ - sport_headlines
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/console
100
+ - bin/setup
101
+ - bin/sport_headlines
102
+ - lib/sport_headlines.rb
103
+ - lib/sport_headlines/article.rb
104
+ - lib/sport_headlines/cli.rb
105
+ - lib/sport_headlines/scraper.rb
106
+ - lib/sport_headlines/site.rb
107
+ - lib/sport_headlines/version.rb
108
+ - notes.md
109
+ - sport_headlines.gemspec
110
+ homepage: https://github.com/cernanb/sport-headlines-cli-gem
111
+ licenses:
112
+ - MIT
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ - lib/sport_headlines
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.4.5.1
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: A gem to collate top sport headlines.
135
+ test_files: []