best_music 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6567e47de1b0ad90672f3f66f58d3b9a661ec57d1a06f2bce594243d2877feae
4
+ data.tar.gz: 9da5ac359ba142893b1d882b84c76bf02a613c682f18487bd38e461a012da762
5
+ SHA512:
6
+ metadata.gz: 0abbdc57138a1f7bfe2b440933d909d241c2c402ca82a0e4e11fcb505487fc2695d6af53c6eba5a2260f9aff5389d3fc12f6498b59cc18c881fa312d9a81ec8e
7
+ data.tar.gz: eaaf2980ce4759517f16b2696848eb48e32ee9a7bb9412f5a5dfdbb6afcd42c7ded33112eb221c3461f0a83b955e42b275fdf6980381be65f5abb89bb830da79
data/.Rhistory ADDED
File without changes
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'pry'
4
+ gem 'nokogiri', '~> 1.8.5'
5
+ gem 'colorize'
6
+
7
+ #git_source(:github) {|| "https://github.com/#{repo_name}" }
8
+
9
+ # Specify your gem's dependencies in best_music.gemspec
10
+ #gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,23 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ coderay (1.1.2)
5
+ colorize (0.8.1)
6
+ method_source (0.9.2)
7
+ mini_portile2 (2.3.0)
8
+ nokogiri (1.8.5)
9
+ mini_portile2 (~> 2.3.0)
10
+ pry (0.12.2)
11
+ coderay (~> 1.1.0)
12
+ method_source (~> 0.9.0)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ colorize
19
+ nokogiri (~> 1.8.5)
20
+ pry
21
+
22
+ BUNDLED WITH
23
+ 1.17.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 cyantis
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,51 @@
1
+ # Best Music
2
+
3
+ _Best Music_ is a CLI app that returns Pitchfork.com's _Best New Albums_ in realtime. It allows easy browsability by genre and score and provides a brief album description and link to the full review online.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'best_music'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install best_music
20
+
21
+ You can also clone or download the repo from GitHub: https://github.com/cyantis/best_music
22
+
23
+ Once you've installed/cloned/downloaded the Gem, run `bin/setup` to install dependencies.
24
+
25
+ ## Usage
26
+
27
+ To launch _Best Music_, simply run `bin/best-music`. The app returns live data from more than a dozen webpages, so it may take a few seconds to launch. Thanks for your patience!
28
+
29
+ Once _Best Music_ has loaded, you will have access to this week's _Best New Album_ along with a number of options for browsing the past 12 weeks' worth of _Best New Albums_. You can:
30
+
31
+ 1. Browse through a list of previous best albums by typing `list`.
32
+ 2. Explore the best albums by genre. Just type `genre`.
33
+ 3. Type `score` to check out the highest scoring albums.
34
+
35
+ If at any point you need a refresher on your options, simply type `help` to access a list of instructions.
36
+
37
+ Once you've finished exploring, type `exit` to quit the program.
38
+
39
+ ## Development
40
+
41
+ After checking out the repo, run `bin/setup` to install dependencies.
42
+
43
+ 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).
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cyantis/best_music.
48
+
49
+ ## License
50
+
51
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,29 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "best_music/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "best_music"
8
+ spec.version = BestMusic::VERSION
9
+ spec.authors = ["cyantis"]
10
+ spec.email = ["cyantis@gmail.com"]
11
+
12
+ spec.summary = %q{A CLI app that returns Pitchfork.com's Best New Albums in realtime.}
13
+ spec.description = %q{A CLI app that returns Pitchfork.com's Best New Albums in realtime. Best Music allows easy browsability by genre and score and provides a brief album description and link to the full review online.}
14
+ spec.homepage = "https://github.com/cyantis/best_music"
15
+ spec.license = "MIT"
16
+
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.17"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ end
data/bin/best-music ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative "../lib/best_music/version"
3
+ require_relative "../lib/environment.rb"
4
+
5
+ BestMusic::CLI.new.call
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "best_music"
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(__FILE__)
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
data/lib/album.rb ADDED
@@ -0,0 +1,24 @@
1
+ require_relative './genre.rb'
2
+
3
+ class Album
4
+ attr_accessor :name, :artist, :genre, :url, :rating, :description
5
+
6
+ @@all = []
7
+
8
+ def initialize(name, artist, genre, url)
9
+ @name = name
10
+ @artist = artist
11
+ @genre = genre
12
+ @url = url
13
+ Genre.all.each {|g| g.albums << self if g.name == genre}
14
+ self.class.all << self
15
+ end
16
+
17
+ def self.all
18
+ @@all
19
+ end
20
+
21
+ def self.albums_by_rating
22
+ all.sort_by {|a| a.rating}.reverse
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module BestMusic
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,90 @@
1
+ require 'colorize'
2
+ require_relative './scraper.rb'
3
+
4
+ module BestMusic
5
+ class CLI
6
+ @@path = 'https://pitchfork.com/reviews/best/albums/'
7
+
8
+ def call
9
+ puts "Welcome to Best Music!".colorize( :background => :green)
10
+ puts "Please wait while we bring you the best new albums according to Pitchfork.com...".red
11
+
12
+ Scraper.album_list(@@path)
13
+ Scraper.album_score
14
+ Scraper.album_description
15
+
16
+ puts "The 'Best New Album' is:"
17
+ puts "*#{Album.all[0].name}* by #{Album.all[0].artist}".colorize(:background => :red)
18
+ puts "It has a score of #{Album.all[0].rating}".yellow
19
+ puts "Pitchfork says: \"#{Album.all[0].description}\""
20
+ puts "To read the full review and/or to learn more visit:"
21
+ puts "https://pitchfork.com#{Album.all[0].url}".green
22
+ puts "______________________".red
23
+ puts "Check out more great music!".yellow
24
+ instructions
25
+
26
+ input = ""
27
+ while input != "exit"
28
+
29
+ puts "What would you like to do?".green
30
+
31
+ input = gets.downcase.chomp
32
+
33
+ case input
34
+ when "list"
35
+ album_list
36
+ when "genre"
37
+ albums_by_genre
38
+ when "score"
39
+ albums_by_rating
40
+ when "help"
41
+ instructions
42
+ end
43
+ end
44
+ end
45
+
46
+ def album_list
47
+ puts "Below are the 'Best New Albums' for the past 12 weeks."
48
+ Album.all.each do |a|
49
+ puts "*#{a.name}* by #{a.artist}".colorize(:background => :red)
50
+ puts "It has a score of #{a.rating}".yellow
51
+ puts "Pitchfork says: \"#{a.description}\""
52
+ puts "To read the full review and/or to learn more visit:"
53
+ puts "https://pitchfork.com#{a.url}".green
54
+ puts "______________________".yellow
55
+ end
56
+ end
57
+
58
+ def albums_by_genre
59
+ Genre.all.each do |g|
60
+ puts "// #{g.name} //".upcase.yellow
61
+ g.albums.each do |a|
62
+ puts "*#{a.name}* by #{a.artist}".colorize(:background => :red)
63
+ puts "It has a score of #{a.rating}".yellow
64
+ puts "Pitchfork says: \"#{a.description}\""
65
+ puts "To read the full review and/or to learn more visit:"
66
+ puts "https://pitchfork.com#{a.url}".green
67
+ puts "----".red
68
+ end
69
+ end
70
+ end
71
+
72
+ def albums_by_rating
73
+ Album.albums_by_rating.each do |a|
74
+ puts "*#{a.name}* by #{a.artist}".colorize(:background => :red)
75
+ puts "It has a score of #{a.rating}".yellow
76
+ puts "Pitchfork says: \"#{a.description}\""
77
+ puts "To read the full review and/or to learn more visit:"
78
+ puts "https://pitchfork.com#{a.url}".green
79
+ puts "______________________".yellow
80
+ end
81
+ end
82
+
83
+ def instructions
84
+ puts "To list all recent 'Best New Albums,' type 'list'."
85
+ puts "To browse by genre, type 'genre'."
86
+ puts "To browse by album score, type 'score'."
87
+ puts "To quit, type 'exit'."
88
+ end
89
+ end
90
+ end
data/lib/genre.rb ADDED
@@ -0,0 +1,20 @@
1
+ class Genre
2
+ attr_accessor :name
3
+
4
+ @@all = []
5
+
6
+ def initialize(name)
7
+ @name = name
8
+ @albums = []
9
+ self.class.all << self
10
+ end
11
+
12
+ def self.all
13
+ @@all
14
+ end
15
+
16
+ def albums
17
+ @albums
18
+ end
19
+
20
+ end
data/lib/scraper.rb ADDED
@@ -0,0 +1,39 @@
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+ require 'pry'
4
+ require_relative './album.rb'
5
+
6
+ #album_list_url = https://pitchfork.com/reviews/best/albums/
7
+
8
+ class Scraper
9
+ def self.scrape_pitchfork(index_url)
10
+ index = Nokogiri::HTML(open(index_url))
11
+ end
12
+
13
+ def self.album_list(index_url)
14
+ a_list = scrape_pitchfork(index_url).css(".fragment-list").css(".review")
15
+ a_list.each do |a|
16
+ album = a.css(".review__title-album").text
17
+ artist = a.css("li")[0].text.gsub("Ã", "ü").gsub("¼", "")
18
+ genre = a.css("li")[1].text
19
+ url = a.css("a").attr("href").value
20
+ Genre.new(genre) if !Genre.all.collect {|g| g.name}.include?(genre)
21
+ Album.new(album, artist, genre, url) if !Album.all.collect {|a| a.name}.include?(album)
22
+ end
23
+ end
24
+
25
+ def self.album_score
26
+ Album.all.each do |a|
27
+ url = "https://pitchfork.com#{a.url}"
28
+ a.rating = scrape_pitchfork(url).css(".score").text.to_f
29
+ end
30
+ end
31
+
32
+ def self.album_description
33
+ Album.all.each do |a|
34
+ url = "https://pitchfork.com#{a.url}"
35
+ description = scrape_pitchfork(url).css(".review-detail__abstract").text.gsub(/\u0099\u0080/, "").gsub(/â€(?=\Ss)/, "'")
36
+ a.description = description.gsub("â€", "--").chomp
37
+ end
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: best_music
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - cyantis
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-04-12 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.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
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
+ description: A CLI app that returns Pitchfork.com's Best New Albums in realtime. Best
42
+ Music allows easy browsability by genre and score and provides a brief album description
43
+ and link to the full review online.
44
+ email:
45
+ - cyantis@gmail.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".Rhistory"
51
+ - ".gitignore"
52
+ - Gemfile
53
+ - Gemfile.lock
54
+ - LICENSE.txt
55
+ - README.md
56
+ - Rakefile
57
+ - best_music.gemspec
58
+ - bin/best-music
59
+ - bin/console
60
+ - bin/setup
61
+ - lib/album.rb
62
+ - lib/best_music/version.rb
63
+ - lib/environment.rb
64
+ - lib/genre.rb
65
+ - lib/scraper.rb
66
+ homepage: https://github.com/cyantis/best_music
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubygems_version: 3.0.1
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: A CLI app that returns Pitchfork.com's Best New Albums in realtime.
89
+ test_files: []