drummingnews_cli_scraper 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: 77695d5cba67a4144b5291f2363aee3a345a97f2
4
+ data.tar.gz: f7efb7641752bf13cac23290ff80dfbe20b20250
5
+ SHA512:
6
+ metadata.gz: 4437a1a8cb3c71fea5547cc0fab5aaf4d4bc2e044fe23b88d2a423134c4274f648f34c08d28527f92a4a615f7aee27fda3a22ed74e5b72b5f6ab3a5a04517222
7
+ data.tar.gz: 3fead02a7cc7b2dc6dfb370aa843cad68dfd1b2e0cdd508ce6a439bfbcf5087a1531ce5d9e0a8bffd4cd8be7468614567115e6b007df49ea8cdb04cbd9bd4948
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/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in drummingnews_cli_scraper.gemspec
6
+
7
+ gemspec
8
+
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 TODO: Write your name
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,19 @@
1
+ # DrummingnewsCliScraper
2
+
3
+ A command line gem that scrapes several drumming publications and displays their contents.
4
+
5
+ ## Installation
6
+
7
+ $ gem install drummingnews_cli_scraper
8
+
9
+ ## Usage
10
+
11
+ Run `drummingnews` to start the interface. You'll see a list of available publications to choose from. Enter the one you'd like to view. This will display the current articles for that magazine. Enter the number for your choice and it will print out.
12
+
13
+ ## Contributing
14
+
15
+ Bug reports and pull requests are welcome on GitHub at https://github.com/bretburau/drummingnews_cli_scraper.
16
+
17
+ ## License
18
+
19
+ 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,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pry'
4
+ require 'nokogiri'
5
+ require 'open-uri'
6
+ require "bundler/setup"
7
+ require "drummingnews_cli_scraper"
8
+
9
+ Modern_drummer = DrummingNews::Magazine.new("Modern Drummer")
10
+ DRUM = DrummingNews::Magazine.new("DRUM!")
11
+ Rhythm = DrummingNews::Magazine.new("Rhythm Magazine")
12
+ Scraper = DrummingNews::Scraper.new
13
+ # You can add fixtures and/or initialization code here to make experimenting
14
+ # with your gem easier. You can also use a different console, if you like.
15
+
16
+ # (If you use this, don't forget to add pry to your Gemfile!)
17
+ # require "pry"
18
+ # Pry.start
19
+
20
+ require "irb"
21
+ IRB.start(__FILE__)
data/bin/drummingnews ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pry'
4
+ require 'nokogiri'
5
+ require 'open-uri'
6
+ require_relative '../lib/drummingnews_cli_scraper.rb'
7
+ puts "\n**********************************\n"
8
+ puts "Welcome to your drumming newsfeed!"
9
+ puts "**********************************"
10
+
11
+ Modern_drummer = DrummingNews::Magazine.new("Modern Drummer")
12
+ DRUM = DrummingNews::Magazine.new("DRUM!")
13
+ Rhythm = DrummingNews::Magazine.new("Rhythm Magazine")
14
+
15
+ DrummingNews::CLI.new.start
16
+
17
+
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,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "drummingnews_cli_scraper/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "drummingnews_cli_scraper"
8
+ spec.version = DrummingnewsCliScraper::VERSION
9
+ spec.authors = ["Bret Burau"]
10
+ spec.email = ["burhooo@gmail.com"]
11
+ spec.summary = "Scraper CLI to display articles for several drumming publications."
12
+ spec.homepage = "https://github.com/bretburau/drummingnews_cli_scraper"
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"] = "https://rubygems.org"
19
+ else
20
+ raise "RubyGems 2.0 or newer is required to protect against " \
21
+ "public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
25
+ f.match(%r{^(test|spec|features)/})
26
+ end
27
+ spec.bindir = "bin"
28
+ spec.executables = ["drummingnews"]#spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_runtime_dependency "pry", '~> 0.10.4'
32
+ spec.add_runtime_dependency 'nokogiri', '~> 1.8', '>= 1.8.1'
33
+ spec.add_development_dependency "bundler", "~> 1.15"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ end
@@ -0,0 +1,11 @@
1
+
2
+
3
+
4
+ module DrummingNews
5
+ require_relative "drummingnews_cli_scraper/version"
6
+ require_relative 'drummingnews_cli_scraper/cli.rb'
7
+ require_relative 'drummingnews_cli_scraper/scraper.rb'
8
+ require_relative 'drummingnews_cli_scraper/article.rb'
9
+ require_relative 'drummingnews_cli_scraper/magazine.rb'
10
+ end
11
+
@@ -0,0 +1,12 @@
1
+ class DrummingNews::Article
2
+ attr_accessor :title, :magazine, :url
3
+ @@all = []
4
+
5
+ def initialize
6
+ @@all << self
7
+ end
8
+
9
+ def self.all
10
+ @@all
11
+ end
12
+ end
@@ -0,0 +1,75 @@
1
+ class DrummingNews::CLI
2
+ attr_accessor :articles, :current_magazine
3
+
4
+ def start
5
+ @scraper = DrummingNews::Scraper.new #Instansiate scraper
6
+ @scraper.scrape_md
7
+ @scraper.scrape_drum
8
+ @scraper.scrape_rhythm
9
+ call
10
+ end
11
+
12
+ def call
13
+ choose_mag
14
+ list_articles
15
+ choose_article
16
+ end
17
+
18
+ def choose_mag
19
+ puts "Which site's articles would you like to view?"
20
+ puts "1. Modern Drummer"
21
+ puts "2. DRUM!"
22
+ puts "3. Rhythm Magazine"
23
+ puts "Or 'exit' to quit"
24
+ mag_choice = ""
25
+ mag_choice = gets.strip
26
+ case mag_choice.downcase
27
+ when "1"
28
+ @articles = Modern_drummer.articles ###Find magazine by title and get articles
29
+ @current_magazine = Modern_drummer
30
+ when "2"
31
+ @articles = DRUM.articles
32
+ @current_magazine = DRUM
33
+ when "3"
34
+ @articles = Rhythm.articles
35
+ @current_magazine = Rhythm
36
+ when "exit"
37
+ exit
38
+ else
39
+ puts "Please enter 1-3 or 'exit'"
40
+ choose_mag
41
+ end
42
+ end
43
+
44
+ def list_articles
45
+ puts "\n------------------------------------------"
46
+ @articles.each_with_index do |article, index|
47
+ puts "#{index + 1}. #{article.title}"
48
+ end
49
+ puts "------------------------------------------\n"
50
+ end
51
+
52
+ def choose_article
53
+ puts "Which one would you like to view? Enter 'back' to go to the main menu, or 'exit' to quit"
54
+ article_choice = gets.strip
55
+ until article_choice.to_i.between?(1, 10) || article_choice.downcase == "back" || article_choice.downcase == "exit" do ###Probably gonna need to change condition to a .length or something
56
+ puts "Please enter a valid article number or 'back'"
57
+ article_choice = gets.strip
58
+ end
59
+ if article_choice.downcase == "back"
60
+ puts ""
61
+ call
62
+ elsif article_choice.downcase == "exit"
63
+ exit
64
+ else
65
+ display_article(article_choice.to_i)
66
+ end
67
+ end
68
+
69
+ def display_article(article_choice)
70
+ article_url = @current_magazine.find(article_choice).url
71
+ article_content = @scraper.scrape_article(article_url, @current_magazine)
72
+ puts article_content
73
+ call
74
+ end
75
+ end
@@ -0,0 +1,21 @@
1
+ class DrummingNews::Magazine
2
+ attr_accessor :name, :articles
3
+ @@all = []
4
+ def initialize(name)
5
+ @articles = []
6
+ @name = name
7
+ @@all << self
8
+ end
9
+
10
+ def self.create(name)
11
+ self.new(name)
12
+ end
13
+
14
+ def find(num)
15
+ @articles[num-1]
16
+ end
17
+
18
+ def self.all
19
+ @@all
20
+ end
21
+ end
@@ -0,0 +1,68 @@
1
+ class DrummingNews::Scraper
2
+ attr_accessor :magazines
3
+
4
+ def scrape_md
5
+ html = open("https://www.moderndrummer.com/")
6
+ doc = Nokogiri::HTML(html)
7
+ doc.css("div.article").first(10).each do |scrape|
8
+ article = DrummingNews::Article.new
9
+ article.title = scrape.css("a.inline-link").text
10
+ article.url = scrape.css("a.inline-link").attribute("href").value
11
+ article.magazine = Modern_drummer
12
+ Modern_drummer.articles << article
13
+ end
14
+ end
15
+
16
+ def scrape_drum
17
+ html = open("http://drummagazine.com/news/")
18
+ doc = Nokogiri::HTML(html)
19
+ doc.css("h2.cb-post-title").each do |scrape|
20
+ article = DrummingNews::Article.new
21
+ article.title = scrape.text
22
+ article.url = scrape.css("a").attribute("href").value
23
+ article.magazine = DRUM
24
+ DRUM.articles << article
25
+ end
26
+ end
27
+
28
+ def scrape_rhythm
29
+ html = open("http://www.musicradar.com/rhythm")
30
+ doc = Nokogiri::HTML(html)
31
+ doc.css(".feature-block a").each do |scrape| #Scrapes header titles
32
+ article = DrummingNews::Article.new
33
+ article.title = scrape.css("span.article-name").text
34
+ article.url = scrape.attribute("href").value
35
+ article.magazine = Rhythm
36
+ Rhythm.articles << article
37
+ end
38
+ doc.css(".listingResult").first(7).each do |scrape| #Scrapes the rest
39
+ article = DrummingNews::Article.new
40
+ article.title = scrape.css("h3").text
41
+ article.url = scrape.css("a").attribute("href")
42
+ article.magazine = Rhythm
43
+ Rhythm.articles << article
44
+ end
45
+ end
46
+
47
+ def scrape_article(url, current_magazine)
48
+ if current_magazine == Modern_drummer #Set up scraping for different magazines
49
+ scrape_css = ".entry-content p"
50
+ elsif current_magazine == DRUM
51
+ scrape_css = ".cb-itemprop p"
52
+ elsif current_magazine == Rhythm
53
+ scrape_css = ".gallery-text p"
54
+ end
55
+ article = ""
56
+ html = open(url)
57
+ doc = Nokogiri::HTML(html)
58
+ doc.css(scrape_css).each do |p|
59
+ article += p.text
60
+ article += "\n\n"
61
+ end
62
+ article += "------------------------------------------\n\n"
63
+ article
64
+ end
65
+
66
+
67
+
68
+ end
@@ -0,0 +1,3 @@
1
+ module DrummingnewsCliScraper
2
+ VERSION = "0.1.0"
3
+ end
data/spec.md ADDED
@@ -0,0 +1,7 @@
1
+ # Specifications for the CLI Assessment
2
+
3
+ Specs:
4
+ - [x] Have a CLI for interfacing with the application
5
+ - [x] Pull data from an external source
6
+ - [x] Implement both list and detail views
7
+
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: drummingnews_cli_scraper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Bret Burau
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-11-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.10.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.10.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.8'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 1.8.1
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '1.8'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 1.8.1
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.15'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.15'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '10.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '10.0'
75
+ description:
76
+ email:
77
+ - burhooo@gmail.com
78
+ executables:
79
+ - drummingnews
80
+ extensions: []
81
+ extra_rdoc_files: []
82
+ files:
83
+ - ".gitignore"
84
+ - Gemfile
85
+ - LICENSE.txt
86
+ - README.md
87
+ - Rakefile
88
+ - bin/console
89
+ - bin/drummingnews
90
+ - bin/setup
91
+ - drummingnews_cli_scraper.gemspec
92
+ - lib/drummingnews_cli_scraper.rb
93
+ - lib/drummingnews_cli_scraper/article.rb
94
+ - lib/drummingnews_cli_scraper/cli.rb
95
+ - lib/drummingnews_cli_scraper/magazine.rb
96
+ - lib/drummingnews_cli_scraper/scraper.rb
97
+ - lib/drummingnews_cli_scraper/version.rb
98
+ - spec.md
99
+ homepage: https://github.com/bretburau/drummingnews_cli_scraper
100
+ licenses:
101
+ - MIT
102
+ metadata:
103
+ allowed_push_host: https://rubygems.org
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.6.7
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Scraper CLI to display articles for several drumming publications.
124
+ test_files: []