npr_best_books 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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/NOTES.md +61 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/npr-best-books +5 -0
- data/bin/setup +8 -0
- data/lib/npr_best_books.rb +7 -0
- data/lib/npr_best_books/book.rb +33 -0
- data/lib/npr_best_books/cli.rb +137 -0
- data/lib/npr_best_books/list.rb +61 -0
- data/lib/npr_best_books/scraper.rb +31 -0
- data/lib/npr_best_books/version.rb +3 -0
- data/npr_best_books.gemspec +28 -0
- metadata +135 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: bb8bcf1372616deddb59c823d1e441abfe1e6675
|
|
4
|
+
data.tar.gz: 128ef1feb7fa2e1e9e543fa8d2dd22571c44b4ec
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: b8129dc8c0782dc74619aaecc7e26d4b6999d6617cf1ff3e66acd31f5a830c282a481840cd8f8bc4a0ed3bfa720fcc721c1eceaac85ae91b995ed3f15e34eaf2
|
|
7
|
+
data.tar.gz: 1817aa5a7d90f32e68975a6316de5354a258e3449361ec6f0bf2f47bae0a40002416ef2c9b8cd1d2ac0a768626448195a343b3dd526e94f60474d63d2e4f3553
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -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 beingy@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
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 beingy
|
|
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/NOTES.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
How to build a CLI Gem
|
|
2
|
+
|
|
3
|
+
1. Plan your gem, imagine your interface
|
|
4
|
+
2. Start with projct structure - google
|
|
5
|
+
3. Start with the entry point - the file run
|
|
6
|
+
4. Force that to build the CLI interface
|
|
7
|
+
5. stub out the interface - fake it until you are ready to make it
|
|
8
|
+
6. start making things real
|
|
9
|
+
7. discover objects
|
|
10
|
+
8. program
|
|
11
|
+
|
|
12
|
+
- A command line interface to access NPR Best Books by year
|
|
13
|
+
|
|
14
|
+
user types npr-best-books
|
|
15
|
+
|
|
16
|
+
show a list of NPR Best Books for Science Fiction & Fantasy from the most recent year.
|
|
17
|
+
|
|
18
|
+
NPR's Latest Best Books Recommendation in Science Fiction & Fantasy from 2015 in Alphabetical Order:
|
|
19
|
+
1. Ancillary Mercy by Ann Leckie
|
|
20
|
+
2. Bitch Planet Vol. 1: Extraordinary Machine by Kelly Sue DeConnick, illustrated by Valentine De Landro
|
|
21
|
+
..
|
|
22
|
+
57. Your Alien by Tammi Sauer, illustrated by Goro Fujita
|
|
23
|
+
|
|
24
|
+
Which book do you want to learn more about? Type 'exit' to end program. Type 'more' to see recommendations from previous years.
|
|
25
|
+
|
|
26
|
+
1
|
|
27
|
+
|
|
28
|
+
Ancillary Mercy by Ann Leckie
|
|
29
|
+
Recommended by Genevieve Valentine, book critic
|
|
30
|
+
It would be a mistake to go into Ancillary Mercy hoping for the same lightning-strike of Ancillary Justice. The first installment of Ann Leckie's trilogy opened a world; by now, things are so complicated for protagonist Breq that all you can hope for is to be satisfied. Luckily, Mercy delivers. The world-building particularly shines in the machinations of this closing chapter, as Breq tries to use her new political powers to stop a war with all the weapons the Radchaai Empire has at its disposal: insinuation, shifting loyalties and the second-best tea set.
|
|
31
|
+
ISBN-13: 978-0316246682
|
|
32
|
+
Paperback: 348 pages
|
|
33
|
+
Publisher: Orbit (October 5, 2015)
|
|
34
|
+
Average Amazon Customer Review: 4.3 out of 5 stars (233 reviews)
|
|
35
|
+
Amazon Buy New Price: $9.59
|
|
36
|
+
|
|
37
|
+
Type 'back' to go back to book list. Type 'exit' to end program. Type 'more' to see recommendations from previous years.
|
|
38
|
+
|
|
39
|
+
#What is a list of books?
|
|
40
|
+
|
|
41
|
+
A list has_many books
|
|
42
|
+
A list has a year
|
|
43
|
+
A list has a genre/title
|
|
44
|
+
|
|
45
|
+
#What is a book?
|
|
46
|
+
|
|
47
|
+
Phase 1 (scrape NPR)
|
|
48
|
+
A book belongs to a list (for now, may belong_to_many lists per cross genre)
|
|
49
|
+
A book has a title
|
|
50
|
+
A book has an author
|
|
51
|
+
A book has a recommender
|
|
52
|
+
A book has a recomendation description
|
|
53
|
+
A book has one or more genres
|
|
54
|
+
|
|
55
|
+
Phrase 2 (scrape Amazon)
|
|
56
|
+
A book has an ISBN
|
|
57
|
+
A book has a publisher
|
|
58
|
+
A book has a number of pages)
|
|
59
|
+
A book has a type (Hardcover or Paperback)
|
|
60
|
+
A book has an Amazon rating
|
|
61
|
+
A book has an Amazon price
|
data/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# NPRBestBooks
|
|
2
|
+
|
|
3
|
+
Welcome to my NPR Book Concierge CLI Gem. Current version will check [NPR's Book Concierge website](http://apps.npr.org/best-books-2015) and retrieve 2015's book recommendations in the Science Fiction and Fantasy genre.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'npr_best_books'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install npr_best_books
|
|
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/beingy/npr_best_books. 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).
|
|
39
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "npr_best_books"
|
|
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/npr-best-books
ADDED
data/bin/setup
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
class NPRBestBooks::Book
|
|
2
|
+
attr_accessor :id, :title, :slug, :author, :genres, :year, :recommender, :bookreview, :isbn, :isbn13, :amazonurl, :amazonratings, :amazonreviews
|
|
3
|
+
|
|
4
|
+
@@books = []
|
|
5
|
+
|
|
6
|
+
def initialize
|
|
7
|
+
@@books << self
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.all
|
|
11
|
+
@@books
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.science_fiction_and_fantasy
|
|
15
|
+
books = self.all.select {|book| book.genres.include?("science-fiction-and-fantasy")}
|
|
16
|
+
books
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.lookup_amazonurl(book)
|
|
20
|
+
book.amazonurl = "https://www.amazon.com/dp/" + book.isbn
|
|
21
|
+
book.amazonurl
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.lookup_amazonreviews(book)
|
|
25
|
+
amazon_url = "https://www.amazon.com/gp/search?keywords=" + book.isbn
|
|
26
|
+
if !book.amazonratings && !book.amazonreviews
|
|
27
|
+
amazon_html = NPRBestBooks::Scraper.lookup_amazon(amazon_url)
|
|
28
|
+
book.amazonratings = amazon_html.css("span[name='#{book.isbn}'] span.a-icon-alt").children.text
|
|
29
|
+
book.amazonreviews = amazon_html.css("div[class='a-row a-spacing-mini']").css("a[class='a-size-small a-link-normal a-text-normal']")[0].children.text
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
require 'pry'
|
|
2
|
+
|
|
3
|
+
class NPRBestBooks::CLI
|
|
4
|
+
attr_accessor :current_book_id, :list, :year
|
|
5
|
+
|
|
6
|
+
def call
|
|
7
|
+
latest_year = NPRBestBooks::List.all_years.last
|
|
8
|
+
@year = latest_year
|
|
9
|
+
@current_book_id = ""
|
|
10
|
+
welcome
|
|
11
|
+
list_books
|
|
12
|
+
menu
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def welcome
|
|
16
|
+
puts "== Welcome to NPR's Book Concierge =="
|
|
17
|
+
puts "== A Guide to #{@year}'s Great Reads =="
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def list_books
|
|
21
|
+
if @list
|
|
22
|
+
puts "#{@year}'s Science Fiction & Fantasy recommendations:"
|
|
23
|
+
@list = NPRBestBooks::List.science_fiction_and_fantasy
|
|
24
|
+
puts "Total #{@year} NPR Science Fiction & Fantasy recommendations: #{@list.count} books"
|
|
25
|
+
else
|
|
26
|
+
NPRBestBooks::List.latest
|
|
27
|
+
puts "#{@year}'s Science Fiction & Fantasy recommendations:"
|
|
28
|
+
@list = NPRBestBooks::List.science_fiction_and_fantasy
|
|
29
|
+
puts "Total #{@year} NPR Science Fiction & Fantasy recommendations: #{@list.count} books"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def menu
|
|
34
|
+
puts "Enter the 'number' of the book you'd like to learn more about, or:"
|
|
35
|
+
puts "'exit' to end program, 'more' to see recommendations from other years"
|
|
36
|
+
print "==> Command: "
|
|
37
|
+
input = ""
|
|
38
|
+
while input != "exit"
|
|
39
|
+
input = gets.strip.downcase
|
|
40
|
+
|
|
41
|
+
if input.to_i >= 1 && input.to_i <= @list.count
|
|
42
|
+
@current_book_id = input.to_i
|
|
43
|
+
current_book_array_id = @current_book_id - 1
|
|
44
|
+
puts "================================================================================"
|
|
45
|
+
puts "=> " + "List ID: #{@current_book_id}"
|
|
46
|
+
puts "=> " + "Title: #{@list[current_book_array_id].title}"
|
|
47
|
+
puts "=> " + "Author: #{@list[current_book_array_id].author}"
|
|
48
|
+
puts "=> " + "Recommended by: #{@list[current_book_array_id].recommender}"
|
|
49
|
+
puts "=> " + "Book Review:"
|
|
50
|
+
bookreview = @list[current_book_array_id].bookreview
|
|
51
|
+
bookreview = bookreview.gsub("<em>","\_")
|
|
52
|
+
bookreview = bookreview.gsub("</em>","\_")
|
|
53
|
+
bookreview_linewrap(bookreview)
|
|
54
|
+
puts "=> " + "ISBN: #{@list[current_book_array_id].isbn}, ISBN-13 #{@list[current_book_array_id].isbn13}"
|
|
55
|
+
puts "=> " + "Average Amazon Customer Reviews:"
|
|
56
|
+
begin
|
|
57
|
+
NPRBestBooks::Book.lookup_amazonreviews(@list[current_book_array_id])
|
|
58
|
+
puts " " + "#{@list[current_book_array_id].amazonratings} (#{@list[current_book_array_id].amazonreviews} Reviews)"
|
|
59
|
+
rescue OpenURI::HTTPError => error
|
|
60
|
+
puts " " + "Data currently unavailable (#{error}). Try again later."
|
|
61
|
+
end
|
|
62
|
+
puts "================================================================================"
|
|
63
|
+
sub_menu
|
|
64
|
+
elsif input.to_s == "list"
|
|
65
|
+
list_books
|
|
66
|
+
menu
|
|
67
|
+
elsif input.to_s == "exit" || input.to_s == "bye" || input.to_s == "quit"
|
|
68
|
+
puts "Exiting program..."
|
|
69
|
+
goodbye
|
|
70
|
+
else
|
|
71
|
+
puts "Invalid command, please try again. Error on: '#{input}'."
|
|
72
|
+
puts "Enter the 'number' of the book you'd want to learn more about, or:"
|
|
73
|
+
puts "'exit' to end program"
|
|
74
|
+
print "==> Command: "
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def sub_menu
|
|
80
|
+
puts "What would you like to do next? Here are your options:"
|
|
81
|
+
puts "Enter a book 'number' from the list to learn more, 'list' to show book list again, 'exit' to end program."
|
|
82
|
+
print "==> Command: "
|
|
83
|
+
input = ""
|
|
84
|
+
while input != "exit" || input != "list" || (input.to_i >= 1 && input.to_i <= @list.count)
|
|
85
|
+
input = gets.strip.downcase
|
|
86
|
+
if input.to_s == "list"
|
|
87
|
+
list_books
|
|
88
|
+
menu
|
|
89
|
+
elsif input.to_s == "more"
|
|
90
|
+
more_menu
|
|
91
|
+
elsif input.to_s == "exit" || input.to_s == "bye" || input.to_s == "quit"
|
|
92
|
+
puts "Exiting program..."
|
|
93
|
+
goodbye
|
|
94
|
+
elsif input.to_i >= 1 && input.to_i <= @list.count
|
|
95
|
+
@current_book_id = input.to_i
|
|
96
|
+
current_book_array_id = @current_book_id - 1
|
|
97
|
+
puts "================================================================================"
|
|
98
|
+
puts "=> " + "List ID: #{@current_book_id}"
|
|
99
|
+
puts "=> " + "Title: #{@list[current_book_array_id].title}"
|
|
100
|
+
puts "=> " + "Author: #{@list[current_book_array_id].author}"
|
|
101
|
+
puts "=> " + "Recommended by: #{@list[current_book_array_id].recommender}"
|
|
102
|
+
puts "=> " + "Book Review:"
|
|
103
|
+
bookreview = @list[current_book_array_id].bookreview
|
|
104
|
+
bookreview = bookreview.gsub("<em>","")
|
|
105
|
+
bookreview = bookreview.gsub("</em>","")
|
|
106
|
+
bookreview_linewrap(bookreview)
|
|
107
|
+
puts "=> " + "ISBN: #{@list[current_book_array_id].isbn}, ISBN-13 #{@list[current_book_array_id].isbn13}"
|
|
108
|
+
puts "=> " + "Average Amazon Customer Reviews:"
|
|
109
|
+
begin
|
|
110
|
+
NPRBestBooks::Book.lookup_amazonreviews(@list[current_book_array_id])
|
|
111
|
+
puts " " + "#{@list[current_book_array_id].amazonratings} (#{@list[current_book_array_id].amazonreviews} Reviews)"
|
|
112
|
+
rescue OpenURI::HTTPError => error
|
|
113
|
+
puts " " + "Data currently unavailable (#{error}). Try again later."
|
|
114
|
+
end
|
|
115
|
+
puts "================================================================================"
|
|
116
|
+
sub_menu
|
|
117
|
+
else
|
|
118
|
+
puts "Invalid command, please try again. Error on: '#{input}'."
|
|
119
|
+
puts "'list' to show book list again, 'exit' to end program."
|
|
120
|
+
print "==> Command: "
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def bookreview_linewrap(string, linewrap_length = 75)
|
|
128
|
+
string_wrapped = string.scan(/\S.{0,#{linewrap_length}}\S(?=\s|$)|\S+/)
|
|
129
|
+
string_wrapped.each {|line| puts " " + "#{line}"}
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def goodbye
|
|
133
|
+
puts "Thank you for checking out NPR's Book Concierge. Goodbye!"
|
|
134
|
+
exit
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
class NPRBestBooks::List
|
|
2
|
+
|
|
3
|
+
attr_accessor :year, :name, :books, :list
|
|
4
|
+
|
|
5
|
+
@@list_years = [ 2015 ]
|
|
6
|
+
|
|
7
|
+
def self.latest
|
|
8
|
+
puts "Loading latest list..."
|
|
9
|
+
#should return a bunch of instances of Book with from latest year.
|
|
10
|
+
if @list
|
|
11
|
+
@list.books
|
|
12
|
+
else
|
|
13
|
+
@list = self.new
|
|
14
|
+
@list.year = @@list_years.last
|
|
15
|
+
@list.name= "#{@list.year}'s Great Reads"
|
|
16
|
+
@list.books = NPRBestBooks::Scraper.books
|
|
17
|
+
|
|
18
|
+
@list.books.each do |book_hash|
|
|
19
|
+
book = NPRBestBooks::Book.new
|
|
20
|
+
book.year = @list.year
|
|
21
|
+
book.genres = book_hash["tags"]
|
|
22
|
+
book.title = book_hash["title"]
|
|
23
|
+
book.slug = book_hash["slug"]
|
|
24
|
+
book.author = book_hash["author"]
|
|
25
|
+
book.recommender = book_hash["reviewer"]
|
|
26
|
+
book.bookreview = book_hash["text"]
|
|
27
|
+
book.isbn = book_hash["isbn"]
|
|
28
|
+
book.isbn13 = book_hash["isbn13"]
|
|
29
|
+
end
|
|
30
|
+
@list.books
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.science_fiction_and_fantasy
|
|
35
|
+
# @list1 assigned to science_fiction_and_fantasy
|
|
36
|
+
if @list1
|
|
37
|
+
@list1.books.each do |book|
|
|
38
|
+
puts "#{book.id}. #{book.title} by #{book.author}"
|
|
39
|
+
end
|
|
40
|
+
@list1.books
|
|
41
|
+
else
|
|
42
|
+
@list1 = self.new
|
|
43
|
+
@list1.year = @@list_years.last
|
|
44
|
+
@list1.name = "Science Fiction and Fantasy"
|
|
45
|
+
@list1.books = NPRBestBooks::Book.science_fiction_and_fantasy
|
|
46
|
+
book_id = 1
|
|
47
|
+
@list1.books.each do |book|
|
|
48
|
+
book.id = book_id
|
|
49
|
+
book.amazonurl = NPRBestBooks::Book.lookup_amazonurl(book)
|
|
50
|
+
puts "#{book.id}. #{book.title} by #{book.author}"
|
|
51
|
+
book_id += 1
|
|
52
|
+
end
|
|
53
|
+
@list1.books
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def self.all_years
|
|
58
|
+
@@list_years
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'nokogiri'
|
|
3
|
+
require 'open-uri'
|
|
4
|
+
require 'json'
|
|
5
|
+
|
|
6
|
+
require 'pry'
|
|
7
|
+
|
|
8
|
+
class NPRBestBooks::Scraper
|
|
9
|
+
|
|
10
|
+
def self.books
|
|
11
|
+
puts "Loading books..."
|
|
12
|
+
html = Nokogiri::HTML(open("http://web.archive.org/web/20160622040558/http://apps.npr.org/best-books-2015/"))
|
|
13
|
+
html_script_data = html.css("script").select {|s| s.children.text.include?("BOOKS") }
|
|
14
|
+
script_data = html_script_data[0].children.text
|
|
15
|
+
all_books = self.parse_data(script_data)
|
|
16
|
+
parsed = JSON.parse(all_books)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.parse_data(data)
|
|
20
|
+
part1 = data.gsub("\n window.BOOKS = [{","[{")
|
|
21
|
+
part2 = part1.gsub("}];","}]")
|
|
22
|
+
part3 = part2.gsub("ANALYTICS.setupChartbeat();","")
|
|
23
|
+
part3
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.lookup_amazon(url)
|
|
27
|
+
amazon_html = Nokogiri::HTML(open(url))
|
|
28
|
+
amazon_html
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
@@ -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 'npr_best_books/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "npr_best_books"
|
|
8
|
+
spec.version = NPRBestBooks::VERSION
|
|
9
|
+
spec.authors = ["beingy"]
|
|
10
|
+
spec.email = ["beingy@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = "CLI Gem to retrieve book recomendations from NPR's Book Concierge website."
|
|
13
|
+
spec.description = "Welcome to my NPR Book Concierge CLI Gem. Current version will check [NPR's Book Concierge website](http://apps.npr.org/best-books-2015) and retrieve 2015's book recommendations in the Science Fiction and Fantasy genre."
|
|
14
|
+
spec.homepage = "https://github.com/beingy/npr-best-books-cli-gem"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
18
|
+
spec.bindir = "exe"
|
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
20
|
+
spec.require_paths = ["lib"]
|
|
21
|
+
|
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
25
|
+
spec.add_runtime_dependency "nokogiri", "~> 1.6"
|
|
26
|
+
spec.add_runtime_dependency "json", "~> 1.8"
|
|
27
|
+
|
|
28
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: npr_best_books
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- beingy
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2016-07-02 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.12'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.12'
|
|
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: '1.6'
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '1.6'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: json
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '1.8'
|
|
76
|
+
type: :runtime
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '1.8'
|
|
83
|
+
description: Welcome to my NPR Book Concierge CLI Gem. Current version will check
|
|
84
|
+
[NPR's Book Concierge website](http://apps.npr.org/best-books-2015) and retrieve
|
|
85
|
+
2015's book recommendations in the Science Fiction and Fantasy genre.
|
|
86
|
+
email:
|
|
87
|
+
- beingy@gmail.com
|
|
88
|
+
executables: []
|
|
89
|
+
extensions: []
|
|
90
|
+
extra_rdoc_files: []
|
|
91
|
+
files:
|
|
92
|
+
- ".gitignore"
|
|
93
|
+
- ".rspec"
|
|
94
|
+
- ".travis.yml"
|
|
95
|
+
- CODE_OF_CONDUCT.md
|
|
96
|
+
- Gemfile
|
|
97
|
+
- LICENSE.txt
|
|
98
|
+
- NOTES.md
|
|
99
|
+
- README.md
|
|
100
|
+
- Rakefile
|
|
101
|
+
- bin/console
|
|
102
|
+
- bin/npr-best-books
|
|
103
|
+
- bin/setup
|
|
104
|
+
- lib/npr_best_books.rb
|
|
105
|
+
- lib/npr_best_books/book.rb
|
|
106
|
+
- lib/npr_best_books/cli.rb
|
|
107
|
+
- lib/npr_best_books/list.rb
|
|
108
|
+
- lib/npr_best_books/scraper.rb
|
|
109
|
+
- lib/npr_best_books/version.rb
|
|
110
|
+
- npr_best_books.gemspec
|
|
111
|
+
homepage: https://github.com/beingy/npr-best-books-cli-gem
|
|
112
|
+
licenses:
|
|
113
|
+
- MIT
|
|
114
|
+
metadata: {}
|
|
115
|
+
post_install_message:
|
|
116
|
+
rdoc_options: []
|
|
117
|
+
require_paths:
|
|
118
|
+
- lib
|
|
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: CLI Gem to retrieve book recomendations from NPR's Book Concierge website.
|
|
135
|
+
test_files: []
|