podcast-book-club 1.0.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: 9e1205d73dcafde5c26f126b8def69ba433e4b18de93da9a74c1d148bd38eba0
4
+ data.tar.gz: 896b55b0410c100e8428fc97e5dc5e8ece3e17eafcf71a89990337232388547b
5
+ SHA512:
6
+ metadata.gz: 48c25a8ea2ad9ba70bc684846528c941f2239c4c2a951faae3151a1335325fafbdc5014e5aa741a5a8fedbcd8994ee7fccf2107e0a7efb9594b8811066c61f81
7
+ data.tar.gz: b46567f4ab1fd88f2a11b8c4be0edc989671da2105ad17bd5b760824499bb2d43a21e404040bdcae41d17500545f824c24f3cc0a5851db0fdff4d7212b9a7e5c
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /spec/
10
+ /config/api.rb
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.1
7
+ before_install: gem install bundler -v 2.0.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at jess.rezac@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in podcast-book-club.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,61 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ podcast-book-club (1.0.0)
5
+ googlebooks (~> 0.0.9)
6
+ nokogiri (~> 1.6, >= 1.6.8)
7
+ rainbow (~> 3.0)
8
+ whirly (~> 0.2.6)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ coderay (1.1.2)
14
+ diff-lcs (1.3)
15
+ googlebooks (0.0.9)
16
+ httparty
17
+ httparty (0.17.0)
18
+ mime-types (~> 3.0)
19
+ multi_xml (>= 0.5.2)
20
+ method_source (0.9.2)
21
+ mime-types (3.2.2)
22
+ mime-types-data (~> 3.2015)
23
+ mime-types-data (3.2019.0331)
24
+ mini_portile2 (2.4.0)
25
+ multi_xml (0.6.0)
26
+ nokogiri (1.10.3)
27
+ mini_portile2 (~> 2.4.0)
28
+ pry (0.12.2)
29
+ coderay (~> 1.1.0)
30
+ method_source (~> 0.9.0)
31
+ rainbow (3.0.0)
32
+ rake (10.5.0)
33
+ rspec (3.8.0)
34
+ rspec-core (~> 3.8.0)
35
+ rspec-expectations (~> 3.8.0)
36
+ rspec-mocks (~> 3.8.0)
37
+ rspec-core (3.8.1)
38
+ rspec-support (~> 3.8.0)
39
+ rspec-expectations (3.8.4)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.8.0)
42
+ rspec-mocks (3.8.1)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.8.0)
45
+ rspec-support (3.8.2)
46
+ unicode-display_width (1.6.0)
47
+ whirly (0.2.6)
48
+ unicode-display_width (~> 1.1)
49
+
50
+ PLATFORMS
51
+ ruby
52
+
53
+ DEPENDENCIES
54
+ bundler (~> 2.0)
55
+ podcast-book-club!
56
+ pry (~> 0.12.2)
57
+ rake (~> 10.0)
58
+ rspec (~> 3.0)
59
+
60
+ BUNDLED WITH
61
+ 2.0.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 <github username>
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,63 @@
1
+ # Podcast Book Club
2
+
3
+ [__The Ezra Klein Show__](https://www.vox.com/ezra-klein-show-podcast) brings you far-reaching conversations about hard problems, big ideas, illuminating theories, and cutting-edge research.
4
+
5
+ __Podcast Book Club__ is a command line interface that scrapes each episode for book recommendations, building a library and allowing the user to explore their bookshelf by genre, author, or keyword.
6
+
7
+ Listen to The Ezra Klein Show at [Player.fm](https://player.fm/series/the-ezra-klein-show/) or check out other [Vox Media Podcasts](https://www.vox.com/pages/podcasts).
8
+
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'podcast-book-club'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install podcast-book-club
25
+
26
+ ## Getting Started
27
+
28
+ Before using Podcast Book Club you must create a new Google Books application. Visit [Google Books APIs](https://developers.google.com/books/docs/v1/using#APIKey) for details.
29
+
30
+ Create a file `config/api.rb` in `config/` and copy and paste the following code:
31
+
32
+ ``` ruby
33
+ # Google Books key
34
+ def googlebooks_config
35
+ {:api_key => <your-api-key>}
36
+ end
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ Type the code below and follow the prompts to explore book recommendations.
42
+
43
+ ``` bash
44
+ $ bin/run
45
+ ```
46
+
47
+ ## Development
48
+
49
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
50
+
51
+ 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).
52
+
53
+ ## Contributing
54
+
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jessrezac/podcast-book-club. 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.
56
+
57
+ ## License
58
+
59
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
60
+
61
+ ## Code of Conduct
62
+
63
+ Everyone interacting in the Podcast Book Club project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/jessrezac/podcast-book-club/blob/master/CODE_OF_CONDUCT.md).
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 "podcast_book_club"
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/run ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ require_relative "../lib/podcast_book_club"
5
+
6
+ PodcastBookClub::CLI.new
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,24 @@
1
+ require "whirly"
2
+
3
+ Whirly.start(spinner: "bouncingBall", color: false, remove_after_stop: true, status: "Opening Podcast Book Club") do
4
+ require "rainbow"
5
+ require "pry"
6
+ require "date"
7
+ require "nokogiri"
8
+ require "open-uri"
9
+ require "googlebooks"
10
+
11
+ require_relative 'api'
12
+ require_relative '../lib/podcast_book_club/cli'
13
+ require_relative '../lib/podcast_book_club/version'
14
+ require_relative '../lib/podcast_book_club/concerns/memorable'
15
+ require_relative '../lib/podcast_book_club/concerns/findable'
16
+ require_relative '../lib/podcast_book_club/concerns/sortable'
17
+ require_relative '../lib/podcast_book_club/scraper'
18
+ require_relative '../lib/podcast_book_club/episode'
19
+ require_relative '../lib/podcast_book_club/book'
20
+ require_relative '../lib/podcast_book_club/author'
21
+ require_relative '../lib/podcast_book_club/genre'
22
+ end
23
+
24
+
@@ -0,0 +1,4 @@
1
+ module PodcastBookClub
2
+ end
3
+
4
+ require_relative '../config/environment'
@@ -0,0 +1,43 @@
1
+ class Author
2
+ attr_accessor :name, :books
3
+
4
+ extend Memorable::ClassMethods
5
+ extend Findable::ClassMethods
6
+ extend Sortable::ClassMethods
7
+ include Memorable::InstanceMethods
8
+
9
+ @@all = []
10
+
11
+ def initialize(attributes)
12
+ @books = []
13
+
14
+ attributes.each do |k,v|
15
+ self.send("#{k}=", v)
16
+ end
17
+
18
+ end
19
+
20
+ def self.all
21
+ @@all
22
+ end
23
+
24
+ def books=(book)
25
+ @books << book unless @books.include?(book)
26
+ end
27
+
28
+ def genres
29
+ @books.map { |book| book.genre }.flatten.uniq
30
+ end
31
+
32
+ def output
33
+
34
+ puts "\n\n" + Rainbow("#{self.name}").bg(:black).yellow.bright + Rainbow(" (#{self.books.count})").silver
35
+
36
+ sorted_books = self.books.sort_by { |book| book.title}
37
+ sorted_books.each do |book|
38
+ puts " #{book.title}"
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -0,0 +1,72 @@
1
+ class Book
2
+ attr_accessor :url, :title, :author, :genre, :episode, :synopsis
3
+
4
+ extend Memorable::ClassMethods
5
+ extend Findable::ClassMethods
6
+ extend Sortable::ClassMethods
7
+ include Memorable::InstanceMethods
8
+
9
+
10
+ @@all = []
11
+
12
+ def initialize(attributes)
13
+ @episode = []
14
+
15
+ attributes.each do |k,v|
16
+ self.send("#{k}=", v) unless v == nil
17
+ end
18
+
19
+ end
20
+
21
+ def self.all
22
+ @@all
23
+ end
24
+
25
+ def episode=(episode)
26
+ episode.add_book(self)
27
+ end
28
+
29
+ def author=(authors)
30
+ @author ||= []
31
+
32
+ if authors.kind_of?(Array)
33
+ authors.each do |a|
34
+ author = Author.find_or_create_by_name(a)
35
+ @author << author
36
+ author.books << self
37
+ end
38
+ else
39
+ author = Author.find_or_create_by_name(authors)
40
+ @author << author
41
+ author.books = self
42
+ end
43
+
44
+ end
45
+
46
+ def genre=(genre)
47
+ @genre ||= []
48
+
49
+ new_genre = Genre.find_or_create_by_name(genre)
50
+ new_genre.add_book(self)
51
+ end
52
+
53
+ def self.find_by_keyword(keyword)
54
+ self.all.select { |book| book.title.downcase.include?(keyword) || book.synopsis.downcase.include?(keyword) unless book.synopsis == nil }
55
+ end
56
+
57
+ def output(number)
58
+ authors = []
59
+ genres = []
60
+
61
+ self.author.each {|a| authors << a.name} unless self.author == [] || self.author == nil
62
+ self.genre.each {|g| genres << g.name} unless self.genre == [] || self.genre == nil
63
+
64
+ puts Rainbow("#{number} - #{self.title}").bg(:black).yellow.bright
65
+ puts Rainbow("Author(s): ").bg(:black).yellow.bright + authors.join(", ") unless authors == []
66
+ puts Rainbow("Genre: ").bg(:black).yellow.bright + genres.join(", ") unless genres == []
67
+ puts Rainbow("Synopsis: ").bg(:black).yellow.bright + "#{self.synopsis}" unless self.synopsis == ""
68
+ puts Rainbow("URL: ").bg(:black).yellow.bright + "#{self.url}\n\n"
69
+ end
70
+
71
+
72
+ end
@@ -0,0 +1,224 @@
1
+ class PodcastBookClub::CLI
2
+
3
+ def initialize
4
+ welcome_message
5
+ @today = Date.today
6
+
7
+ Whirly.start(spinner: "pencil", color: false, remove_after_stop: true, status: "Loading Episodes") do
8
+ @scraper = Scraper.new
9
+ end
10
+
11
+ call
12
+ end
13
+
14
+ def call
15
+
16
+ until @input == "exit"
17
+
18
+ menu_options
19
+
20
+ puts "\n\nEnter your selection:"
21
+ @input = gets.chomp.downcase
22
+
23
+ case @input
24
+ when "1", "this week"
25
+ first_date = @today - @today.wday
26
+ episodes = Episode.find_by_date(first_date, @today)
27
+
28
+ select_episodes(episodes)
29
+
30
+ when "2", "last week"
31
+ first_date = @today - @today.wday - 7
32
+ last_date = @today - @today.wday
33
+ episodes = Episode.find_by_date(first_date, last_date)
34
+
35
+ select_episodes(episodes)
36
+
37
+ when "3", "this month"
38
+ first_date = @today - @today.mday + 1
39
+ episodes = Episode.find_by_date(first_date, @today)
40
+
41
+ select_episodes(episodes)
42
+
43
+ when "4", "last month"
44
+ last_date = @today - @today.mday
45
+ first_date = last_date - last_date.mday + 1
46
+ episodes = Episode.find_by_date(first_date, last_date)
47
+
48
+ select_episodes(episodes)
49
+
50
+ when "5", "this year"
51
+ first_date = @today - @today.yday + 1
52
+ episodes = Episode.find_by_date(first_date, @today)
53
+
54
+ select_episodes(episodes)
55
+
56
+ when "6", "keyword"
57
+ puts "\n\nEnter a keyword or phrase:"
58
+ keyword = gets.chomp.downcase
59
+ episodes = Episode.find_by_keyword(keyword)
60
+
61
+ select_episodes(episodes)
62
+
63
+ when "7", "author"
64
+
65
+ if Book.count > 0
66
+ Author.sort_by_name.each { |author| author.output }
67
+ else
68
+ no_books
69
+ end
70
+
71
+ when "8", "genre"
72
+
73
+ if Book.count > 0
74
+ Genre.sort_by_name.each { |genre| genre.output }
75
+ else
76
+ no_books
77
+ end
78
+
79
+ when "9", "search"
80
+
81
+ if Book.count > 0
82
+ puts "\n\nEnter a keyword or phrase:"
83
+ keyword = gets.chomp.downcase
84
+ books = Book.find_by_keyword(keyword)
85
+
86
+ books.each_with_index do |book, i|
87
+ episodes = book.episode.map { |ep| ep.title}
88
+
89
+ book.output(i+1)
90
+ puts "From the episode(s): #{episodes.join(", ")}\n\n"
91
+ end
92
+
93
+ else
94
+ no_books
95
+ end
96
+
97
+ when "animal style"
98
+ create_library(Episode.all)
99
+
100
+ when "help"
101
+ menu_options
102
+
103
+ when "exit"
104
+ break
105
+
106
+ else
107
+ unexpected_input
108
+
109
+ end
110
+
111
+ end
112
+
113
+ end
114
+
115
+
116
+ def create_library(episodes)
117
+ episodes.each do |episode|
118
+
119
+ @scraper.build_books(episode) unless episode.books != []
120
+
121
+ puts "\n\nHere are the recommendations from \"#{episode.title}\":\n\n"
122
+
123
+ episode.books.each_with_index do |book, i|
124
+ book.output(i+1)
125
+ end
126
+ end
127
+ end
128
+
129
+ def select_episodes(episodes)
130
+
131
+ until @selection == "exit" || @selection == "back"
132
+ select_menu(episodes)
133
+ @selection = gets.chomp.downcase
134
+
135
+ case @selection
136
+ when /\d/
137
+ unless @selection.to_i > episodes.count
138
+ selected_episodes = [episodes[@selection.to_i - 1]]
139
+ create_library(selected_episodes)
140
+
141
+ else
142
+ unexpected_input
143
+ select_menu(episodes)
144
+ @selection = gets.chomp.downcase
145
+
146
+ end
147
+
148
+ when "all"
149
+ create_library(episodes)
150
+ when "back"
151
+ call
152
+ when "exit"
153
+ @input = "exit"
154
+ else
155
+ unexpected_input
156
+ end
157
+
158
+ end
159
+
160
+ end
161
+
162
+ private
163
+ def welcome_message
164
+ puts Rainbow(" _ _ _ _ _ _
165
+ _ __ ___ __| | ___ __ _ ___| |_ | |__ ___ ___ | | __ ___| |_ _| |__
166
+ | '_ \\ / _ \\ / _` |/ __/ _` / __| __| | '_ \\ / _ \\ / _ \\| |/ / / __| | | | | '_ \\
167
+ | |_) | (_) | (_| | (_| (_| \\__ \\ |_ | |_) | (_) | (_) | < | (__| | |_| | |_) |
168
+ | .__/ \\___/ \\__,_|\\___\\__,_|___/\\__| |_.__/ \\___/ \\___/|_|\\_\\ \\___|_|\\__,_|_.__/
169
+ |_|
170
+
171
+ ").bg(:black).yellow.bright
172
+
173
+ puts Rainbow(" The Ezra Klein Show ").black.bg(:yellow).bright + " brings you far-reaching conversations about hard problems, big ideas,"
174
+ puts "illuminating theories, and cutting-edge research.\n\n"
175
+ puts Rainbow(" Podcast Book Club ").black.bg(:yellow).bright + " lets you climb around the guests' bookshelves."
176
+ puts "Let's get started!\n\n"
177
+ end
178
+
179
+ def menu_options
180
+
181
+ puts "\n\nList episodes:"
182
+ puts "1. from 'this week'"
183
+ puts "2. from 'last week'"
184
+ puts "3. from 'this month'"
185
+ puts "4. from 'last month'"
186
+ puts "5. from 'this year'"
187
+ puts "6. by 'keyword'"
188
+
189
+ if Book.count > 0
190
+ puts "\n\n" + Rainbow("It looks like you've found some books!").black.bg(:yellow).bright
191
+ puts "Explore bookshelf:"
192
+ puts "7. by 'author'"
193
+ puts "8. by 'genre'"
194
+ puts "9. 'search'"
195
+ end
196
+
197
+ puts "\n\n'help' for options or 'exit'"
198
+
199
+ end
200
+
201
+ def unexpected_input
202
+ puts "\n\nSorry, I did not understand your response."
203
+ puts "What would you like to do?"
204
+ end
205
+
206
+ def puts_episodes(episodes)
207
+ puts "\n\nI have found " + Rainbow(episodes.count).bg(:black).yellow.bright + " episode(s).\n\n"
208
+ episodes.each.with_index { |episode, i| episode.output(i+1) }
209
+ end
210
+
211
+ def select_menu(episodes)
212
+ puts_episodes(episodes)
213
+
214
+ puts "\n\nEnter the number of the episode to see recommended books or enter 'all' to create a library from all listed episodes."
215
+ puts "Use 'back' for previous menu or 'exit' to close program."
216
+ puts "\n\nWhat would you like to do?"
217
+ end
218
+
219
+ def no_books
220
+ puts "Your library has no books! Find an episode to begin building your library."
221
+ menu_options
222
+ end
223
+
224
+ end
@@ -0,0 +1,30 @@
1
+ module Findable
2
+ module ClassMethods
3
+ def find_by_name(name)
4
+ self.all.detect {|i| i.name == name}
5
+ end
6
+
7
+ def find_by_title(title)
8
+ self.all.detect {|i| i.title.downcase.include?(title.downcase)}
9
+ end
10
+
11
+ def find_or_create_by_name(name)
12
+ instance = self.find_by_name(name) || self.create({name: name})
13
+ instance
14
+ end
15
+
16
+ def find_or_create_by_title(attributes)
17
+ title = attributes[:title]
18
+
19
+ if self.find_by_title(title)
20
+ instance = self.find_by_title
21
+ instance.episode = attributes[:episode]
22
+ else
23
+ self.create(attributes)
24
+ end
25
+
26
+ instance
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,28 @@
1
+ module Memorable
2
+
3
+ module InstanceMethods
4
+
5
+ def save
6
+ self.class.all << self
7
+ end
8
+
9
+ end
10
+
11
+ module ClassMethods
12
+
13
+ def destroy_all
14
+ self.all.clear
15
+ end
16
+
17
+ def count
18
+ self.all.count
19
+ end
20
+
21
+ def create(attributes)
22
+ instance = self.new(attributes)
23
+ instance.save
24
+ instance
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,13 @@
1
+ module Sortable
2
+
3
+ module ClassMethods
4
+ def sort_by_title
5
+ self.all.sort {|left, right| left.title <=> right.title}
6
+ end
7
+
8
+ def sort_by_name
9
+ self.all.sort {|left, right| left.name <=> right.name}
10
+ end
11
+ end
12
+
13
+ end
@@ -0,0 +1,45 @@
1
+ class Episode
2
+ attr_accessor :title, :link, :description, :date, :books
3
+
4
+ extend Memorable::ClassMethods
5
+ extend Findable::ClassMethods
6
+ extend Sortable::ClassMethods
7
+ include Memorable::InstanceMethods
8
+
9
+
10
+ @@all = []
11
+
12
+ def initialize(attributes)
13
+ @books = []
14
+
15
+ attributes.each do |k, v|
16
+ self.send("#{k}=", v)
17
+ end
18
+
19
+ end
20
+
21
+ def self.all
22
+ @@all
23
+ end
24
+
25
+ def add_book(book)
26
+ self.books << book unless self.books.include?(book)
27
+ book.episode << self unless book.episode.include?(self)
28
+ books
29
+ end
30
+
31
+ def self.find_by_keyword(keyword)
32
+ self.all.select { |ep| ep.title.downcase.include?(keyword) }
33
+ end
34
+
35
+
36
+ def self.find_by_date(first_date, last_date)
37
+ self.all.select { |ep| ep.date >= first_date && ep.date <= last_date }
38
+ end
39
+
40
+ def output(number, display_description = false)
41
+ puts "#{number} - " + Rainbow("#{self.title}").bg(:black).yellow.bright + " - #{self.date}"
42
+ puts "#{self.description}" if display_description == true
43
+ end
44
+
45
+ end
@@ -0,0 +1,52 @@
1
+ class Genre
2
+ attr_accessor :name, :books
3
+
4
+ extend Memorable::ClassMethods
5
+ extend Findable::ClassMethods
6
+ extend Sortable::ClassMethods
7
+ include Memorable::InstanceMethods
8
+
9
+
10
+ @@all = []
11
+
12
+ def initialize(attributes)
13
+
14
+ @books = []
15
+
16
+ attributes.each do |k,v|
17
+ self.send("#{k}=", v)
18
+ end
19
+
20
+ end
21
+
22
+ def self.all
23
+ @@all
24
+ end
25
+
26
+ def books=(book)
27
+ self.books << book
28
+ end
29
+
30
+ def add_book(book)
31
+ self.books << book unless self.books.include?(book)
32
+ book.genre << self unless book.genre.include?(self)
33
+ books
34
+ end
35
+
36
+ def authors
37
+ @books.map { |book| book.author }.flatten.uniq
38
+ end
39
+
40
+ def output
41
+ puts "\n\n" + Rainbow("#{self.name}").bg(:black).yellow.bright + " (#{self.books.count})"
42
+
43
+ sorted_books = self.books.sort_by { |book| book.title}
44
+ sorted_books.each do |book|
45
+ authors = []
46
+ book.author.each { |author| authors << author.name}
47
+
48
+ puts " #{book.title} by #{authors.join(", ")}"
49
+ end
50
+ end
51
+
52
+ end
@@ -0,0 +1,153 @@
1
+ require_relative "../podcast_book_club.rb"
2
+
3
+ class Scraper
4
+
5
+ def initialize
6
+ path = build_path
7
+ fetch_episodes(path)
8
+ @config = googlebooks_config
9
+ end
10
+
11
+ def fetch_episodes(path)
12
+ html = open(path)
13
+ doc = Nokogiri::HTML(html, nil, Encoding::UTF_8.to_s)
14
+ episodes = doc.css(".info")
15
+
16
+ episodes.each do |episode|
17
+
18
+ title = episode.css(".info-top a").text.strip
19
+ link = "https://player.fm#{episode.css(".info-top a").attribute("href").value}"
20
+ date = Date.strptime(episode.css(".timeago").attribute("datetime").value)
21
+
22
+ attributes = {
23
+ title: title,
24
+ link: link,
25
+ date: date
26
+ }
27
+
28
+ Episode.create(attributes)
29
+ end
30
+
31
+ end
32
+
33
+ def build_books(episode)
34
+ describe_episode(episode)
35
+
36
+ if @description.match?(/\b(B|b)ook/)
37
+ queries = send_to_parser(episode)
38
+
39
+ queries.each do |query|
40
+ google_book_search = GoogleBooks.search(query, @config)
41
+ result = google_book_search.first
42
+
43
+ attributes = {}
44
+
45
+ begin
46
+
47
+ attributes[:url] = result.info_link unless result.info_link.nil?
48
+ attributes[:title] = result.title unless result.title.nil?
49
+ attributes[:author] = result.authors_array unless result.authors_array.nil? || result.authors_array == [nil]
50
+ attributes[:genre] = result.categories unless result.categories.nil? || result.categories == ""
51
+ attributes[:synopsis] = result.description unless result.description.nil?
52
+ attributes[:episode] = episode
53
+
54
+ Book.find_or_create_by_title(attributes)
55
+
56
+ rescue
57
+
58
+ puts "I'm having trouble adding the book " + Rainbow("#{query}").bg(:black).yellow + "from episode: #{episode.output(Episode.all.index(episode))}."
59
+
60
+ end
61
+ end
62
+ end
63
+
64
+ end
65
+
66
+ def build_path
67
+ snapshot_date = Date.new(2019,6,25)
68
+ today = Date.today
69
+ episodes_since_snapshot = snapshot_date.step(today).select{|d| d.monday? || d.thursday?}.size
70
+ url = "https://player.fm/series/the-ezra-klein-show/episodes?active=true&limit=#{episodes_since_snapshot + 183}&order=newest&query=&style=list&container=false&offset=0"
71
+ end
72
+
73
+ def describe_episode(episode)
74
+ path = episode.link
75
+
76
+ html = open(path)
77
+ @episode_doc = Nokogiri::HTML(html)
78
+ @description = @episode_doc.css(".story .description").text
79
+ end
80
+
81
+ def send_to_parser(episode)
82
+ today = Date.today
83
+ with_links = Date.new(2019, 1, 14)
84
+ without_links = Date.new(2017, 3, 28)
85
+
86
+ case episode.date
87
+ when (with_links..today)
88
+ parse_with_links(episode)
89
+ when (without_links...with_links)
90
+ parse_without_links(episode)
91
+ else
92
+ puts "This episode has no recommendations."
93
+ end
94
+
95
+ end
96
+
97
+ def parse_with_links(episode)
98
+ book_titles = []
99
+
100
+ book_links = @episode_doc.css(".description.prose > a")
101
+
102
+ book_links.map do |link|
103
+ if link.attribute("href").value.include?("amazon")
104
+ book_titles << link.text
105
+ end
106
+ end
107
+
108
+ description = @description.split(book_titles[0]).pop.to_s
109
+
110
+ books = []
111
+
112
+ book_titles.map.with_index do |title, i|
113
+ unless i + 1 == book_titles.length
114
+ description = description.split(book_titles[i+1 || i])
115
+ author = description[0].strip
116
+
117
+ books << "#{title} #{author}"
118
+
119
+ description = description.pop
120
+
121
+ else
122
+
123
+ books << "#{title} #{description[0].strip}"
124
+
125
+ end
126
+
127
+ end
128
+
129
+ books
130
+
131
+ end
132
+
133
+ def parse_without_links(episode)
134
+ book_block = @description.split(/(B|b)ooks:?\s/)[-1]
135
+ book_block = book_block.split("Notes from our sponsors")[0]
136
+ books = book_block.split(/Find.*ART19/)[0]
137
+
138
+ book_array = books.strip.split(/\sby(\s[A-Z]\w*\s[a-z]*\s?[A-Z][.\w]*(?<![a-z])\s?[A-Z]?[.a-zA-Z]*)/)
139
+
140
+ book_queries = []
141
+
142
+ book_array.map.with_index do |item, i|
143
+ if i.even?
144
+ book_queries << "#{item.strip} #{book_array[i+1]}"
145
+ end
146
+ end
147
+
148
+ book_queries
149
+
150
+ end
151
+
152
+ end
153
+
@@ -0,0 +1,3 @@
1
+ module PodcastBookClub
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,39 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "podcast_book_club/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "podcast-book-club"
7
+ spec.version = PodcastBookClub::VERSION
8
+ spec.authors = ["jessrezac"]
9
+ spec.email = ["jess.rezac@gmail.com"]
10
+
11
+ spec.summary = %q{The Ezra Klein Show book recommendations.}
12
+ spec.description = %q{Explore books recommended by guests on The Ezra Klein Show on Vox.}
13
+ spec.homepage = "https://github.com/jessrezac/podcast-book-club"
14
+ spec.license = "MIT"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/jessrezac/podcast-book-club"
18
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 2.0"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rspec", "~> 3.0"
32
+ spec.add_development_dependency "pry", "~> 0.12.2"
33
+
34
+ spec.add_dependency "nokogiri", "~> 1.6", ">= 1.6.8"
35
+ spec.add_dependency "googlebooks", "~> 0.0.9"
36
+ spec.add_dependency "whirly", "~> 0.2.6"
37
+ spec.add_dependency "rainbow", "~> 3.0"
38
+
39
+ end
metadata ADDED
@@ -0,0 +1,188 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: podcast-book-club
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - jessrezac
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-07-14 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.12.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.12.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.6'
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 1.6.8
79
+ type: :runtime
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - "~>"
84
+ - !ruby/object:Gem::Version
85
+ version: '1.6'
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 1.6.8
89
+ - !ruby/object:Gem::Dependency
90
+ name: googlebooks
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: 0.0.9
96
+ type: :runtime
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 0.0.9
103
+ - !ruby/object:Gem::Dependency
104
+ name: whirly
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: 0.2.6
110
+ type: :runtime
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: 0.2.6
117
+ - !ruby/object:Gem::Dependency
118
+ name: rainbow
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '3.0'
124
+ type: :runtime
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '3.0'
131
+ description: Explore books recommended by guests on The Ezra Klein Show on Vox.
132
+ email:
133
+ - jess.rezac@gmail.com
134
+ executables: []
135
+ extensions: []
136
+ extra_rdoc_files: []
137
+ files:
138
+ - ".gitignore"
139
+ - ".rspec"
140
+ - ".travis.yml"
141
+ - CODE_OF_CONDUCT.md
142
+ - Gemfile
143
+ - Gemfile.lock
144
+ - LICENSE.txt
145
+ - README.md
146
+ - Rakefile
147
+ - bin/console
148
+ - bin/run
149
+ - bin/setup
150
+ - config/environment.rb
151
+ - lib/podcast_book_club.rb
152
+ - lib/podcast_book_club/author.rb
153
+ - lib/podcast_book_club/book.rb
154
+ - lib/podcast_book_club/cli.rb
155
+ - lib/podcast_book_club/concerns/findable.rb
156
+ - lib/podcast_book_club/concerns/memorable.rb
157
+ - lib/podcast_book_club/concerns/sortable.rb
158
+ - lib/podcast_book_club/episode.rb
159
+ - lib/podcast_book_club/genre.rb
160
+ - lib/podcast_book_club/scraper.rb
161
+ - lib/podcast_book_club/version.rb
162
+ - podcast_book_club.gemspec
163
+ homepage: https://github.com/jessrezac/podcast-book-club
164
+ licenses:
165
+ - MIT
166
+ metadata:
167
+ homepage_uri: https://github.com/jessrezac/podcast-book-club
168
+ source_code_uri: https://github.com/jessrezac/podcast-book-club
169
+ post_install_message:
170
+ rdoc_options: []
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ requirements: []
184
+ rubygems_version: 3.0.4
185
+ signing_key:
186
+ specification_version: 4
187
+ summary: The Ezra Klein Show book recommendations.
188
+ test_files: []