goodreads-books 0.1.3 → 0.1.4
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 +4 -4
- data/lib/goodreads_books/cli.rb +12 -14
- data/lib/goodreads_books/scraper.rb +4 -3
- data/lib/goodreads_books/version.rb +1 -1
- metadata +7 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f3b05f532720098a0eb7af52b1f443f2e7baac68b65be53d2459e9d0736b583
|
4
|
+
data.tar.gz: 1872712dda4cfa6f6c1bb09786e413bc6b2d1e156f96954bed24a8367ecc11e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f7e93ee5608169e1e7e04a9f57a0df7dd41cb5941640f87556b7f98b83a875ad0c23e99ebb5baa91e98f6b2fa744a90eec2ef1bb445c6a3f5414436ba062a09
|
7
|
+
data.tar.gz: a2852ad39d195ec22ac3f31e805b7819a30214571b7720cccc9ddfc099530a8e738fc70c3443b187a5c26cb8376def767150c930506ad464bdd701e551ac3737
|
data/lib/goodreads_books/cli.rb
CHANGED
@@ -7,8 +7,8 @@ class GoodreadsBooks::CLI
|
|
7
7
|
def call
|
8
8
|
system "clear"
|
9
9
|
puts ""
|
10
|
-
puts "---------- Welcome to Goodreads Choice Awards
|
11
|
-
puts "
|
10
|
+
puts "---------- Welcome to Goodreads Choice Awards ----------"
|
11
|
+
puts " ----------------------------------"
|
12
12
|
puts ""
|
13
13
|
|
14
14
|
@latest_awards_year = GoodreadsBooks::Scraper.scrape_awards_year
|
@@ -19,7 +19,7 @@ class GoodreadsBooks::CLI
|
|
19
19
|
|
20
20
|
def load_choice_awards_books(awards_year)
|
21
21
|
@awards_year = awards_year
|
22
|
-
puts "Loading The Winners
|
22
|
+
puts "Loading The Goodreads Choice Awards Winners for #{awards_year} ..."
|
23
23
|
if GoodreadsBooks::Book.find_all_by_year(awards_year).empty?
|
24
24
|
GoodreadsBooks::Scraper.scrape_books(awards_year)
|
25
25
|
end
|
@@ -32,14 +32,14 @@ class GoodreadsBooks::CLI
|
|
32
32
|
book_count = GoodreadsBooks::Book.find_all_by_year(@awards_year).count
|
33
33
|
list_books
|
34
34
|
|
35
|
+
puts ""
|
35
36
|
if !valid_input
|
36
|
-
puts ""
|
37
|
-
puts "
|
37
|
+
puts "Please enter the book number to see more information:".colorize(:red)
|
38
|
+
puts "(You can also enter another Choice Awards year of 2010 or later, or type 'exit')".colorize(:red)
|
38
39
|
valid_input = true
|
39
40
|
else
|
40
|
-
puts ""
|
41
|
-
puts "
|
42
|
-
puts "Type 'exit' to end the application.".colorize(:green)
|
41
|
+
puts "Please enter the book number to see more information:".colorize(:green)
|
42
|
+
puts "(You can also enter another Choice Awards year of 2010 or later, or type 'exit')".colorize(:green)
|
43
43
|
end
|
44
44
|
|
45
45
|
input = gets.strip
|
@@ -60,17 +60,17 @@ class GoodreadsBooks::CLI
|
|
60
60
|
end
|
61
61
|
|
62
62
|
puts ""
|
63
|
-
puts "Thank you for using Goodreads Choice Awards
|
63
|
+
puts "Thank you for using the Goodreads Choice Awards Application."
|
64
64
|
end #-- main_menu --
|
65
65
|
|
66
66
|
def list_books
|
67
67
|
system "clear"
|
68
68
|
puts ""
|
69
|
-
puts "---------- #{@awards_year} Goodreads Choice Awards
|
69
|
+
puts "---------- #{@awards_year} Goodreads Choice Awards Winners----------"
|
70
70
|
puts ""
|
71
71
|
|
72
72
|
GoodreadsBooks::Book.find_all_by_year(@awards_year).each.with_index(1) do |book, index|
|
73
|
-
puts "#{index}. #{book.category}
|
73
|
+
puts "#{index}. #{book.category}: #{book.title}"
|
74
74
|
end
|
75
75
|
end #-- display_books --
|
76
76
|
|
@@ -82,9 +82,7 @@ class GoodreadsBooks::CLI
|
|
82
82
|
puts "Title: #{book.title}"
|
83
83
|
puts "Author: #{book.author}"
|
84
84
|
puts "Votes: #{book.vote}"
|
85
|
-
puts ""
|
86
|
-
puts " --- Description ---"
|
87
|
-
puts "#{book.description}"
|
85
|
+
puts "Description: #{book.description}"
|
88
86
|
|
89
87
|
puts ""
|
90
88
|
puts "Would you like to open Goodreads website to view this book? Enter Y to open the website.".colorize(:green)
|
@@ -14,10 +14,11 @@ class GoodreadsBooks::Scraper
|
|
14
14
|
def self.scrape_books(awards_year)
|
15
15
|
main_url = "#{BASE_URL}#{PAGE_URL}/best-books-#{awards_year}"
|
16
16
|
doc = Nokogiri::HTML(open(main_url))
|
17
|
+
# binding.pry
|
17
18
|
|
18
19
|
# Category winners page: iterate through the best book of each category and collect the book information
|
19
20
|
doc.css(".category.clearFix").collect do |category|
|
20
|
-
category_name = category.css("h4").text
|
21
|
+
category_name = category.css("h4").text.split("\n")[1]
|
21
22
|
category_url = category.css("a").attr("href").text
|
22
23
|
category_title = category.css("img").attr("alt").text
|
23
24
|
|
@@ -38,8 +39,8 @@ class GoodreadsBooks::Scraper
|
|
38
39
|
book_doc = Nokogiri::HTML(open(book.category_url))
|
39
40
|
|
40
41
|
book.vote = book_doc.css(".gcaRightContainer .gcaWinnerHeader").text.split(" ")[1]
|
41
|
-
book.author = book_doc.css(".gcaRightContainer
|
42
|
-
book.url = "#{BASE_URL}#{book_doc.css(".gcaRightContainer
|
42
|
+
book.author = book_doc.css(".gcaRightContainer .gcaAuthor a.authorName").text
|
43
|
+
book.url = "#{BASE_URL}#{book_doc.css(".gcaRightContainer a.winningTitle").attr("href").text}"
|
43
44
|
|
44
45
|
# goodreads description is encoded, so need to add .encode("ISO-8859-1") to print the special characters eg. â\u0080\u0099s in printable character of '
|
45
46
|
# if self.awards_year < 2017, use the span tag, else there's no span tag so don't check for it
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: goodreads-books
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ni Chia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -70,16 +70,16 @@ dependencies:
|
|
70
70
|
name: nokogiri
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 1.8.5
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 1.8.5
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: colorize
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,8 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '0'
|
132
132
|
requirements: []
|
133
|
-
|
134
|
-
rubygems_version: 2.7.6
|
133
|
+
rubygems_version: 3.0.3
|
135
134
|
signing_key:
|
136
135
|
specification_version: 4
|
137
136
|
summary: Goodreads Choice Awards Books
|