libri 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/Gemfile.lock +7 -1
- data/lib/.DS_Store +0 -0
- data/lib/libri.rb +1 -0
- data/lib/libri/awards.rb +2 -2
- data/lib/libri/book.rb +2 -2
- data/lib/libri/books.rb +2 -2
- data/lib/libri/cli.rb +13 -38
- data/lib/libri/quote.rb +2 -2
- data/lib/libri/scraper.rb +12 -35
- data/lib/libri/version.rb +1 -1
- data/libri-0.2.4.gem +0 -0
- data/libri.gemspec +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e6cf633c033f6eb4ac59761da225df2d483d12665a994a921511e1a1b3e295e
|
4
|
+
data.tar.gz: f8428c1ccd9130a7f14437db3c72eb54e88d4c2bc192f92ae222735374ec6f3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b60e09d2b22c41ef4cabf181771631513dd11b17b725de7e81ea5c501156f49b32c5b80b7a13908e72b8d0519e63c9f83e01ab49352f62617831bd9bd7a5487a
|
7
|
+
data.tar.gz: 6676124503246e60492b212af94a7e52f36505c65a444966fa8667ca05413111bd5fcc19eb3b008bef29c1d1dda99cb2e8fb4aa89b51e04bcbe3e8634bc9df64
|
data/.DS_Store
CHANGED
Binary file
|
data/Gemfile.lock
CHANGED
@@ -1,19 +1,24 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
libri (0.2.
|
4
|
+
libri (0.2.5)
|
5
5
|
colorize
|
6
6
|
nokogiri (~> 1.8.3)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
+
coderay (1.1.2)
|
11
12
|
colorize (0.8.1)
|
12
13
|
diff-lcs (1.3)
|
13
14
|
gem-release (2.0.1)
|
15
|
+
method_source (0.9.0)
|
14
16
|
mini_portile2 (2.3.0)
|
15
17
|
nokogiri (1.8.3)
|
16
18
|
mini_portile2 (~> 2.3.0)
|
19
|
+
pry (0.11.3)
|
20
|
+
coderay (~> 1.1.0)
|
21
|
+
method_source (~> 0.9.0)
|
17
22
|
rake (10.5.0)
|
18
23
|
rspec (3.7.0)
|
19
24
|
rspec-core (~> 3.7.0)
|
@@ -36,6 +41,7 @@ DEPENDENCIES
|
|
36
41
|
bundler (~> 1.16)
|
37
42
|
gem-release
|
38
43
|
libri!
|
44
|
+
pry
|
39
45
|
rake (~> 10.0)
|
40
46
|
rspec (~> 3.0)
|
41
47
|
|
data/lib/.DS_Store
CHANGED
Binary file
|
data/lib/libri.rb
CHANGED
data/lib/libri/awards.rb
CHANGED
@@ -4,14 +4,14 @@ class Libri::Awards
|
|
4
4
|
@@all = []
|
5
5
|
|
6
6
|
def initialize(awards_hash)
|
7
|
-
awards_hash.
|
7
|
+
awards_hash.map { |key, val|
|
8
8
|
send "#{key}=", val
|
9
9
|
}
|
10
10
|
@@all << self
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.create_from_collection(awards_array)
|
14
|
-
awards_array.
|
14
|
+
awards_array.map { |awards_hash|
|
15
15
|
self.new(awards_hash)
|
16
16
|
}
|
17
17
|
end
|
data/lib/libri/book.rb
CHANGED
@@ -4,14 +4,14 @@ class Libri::Book
|
|
4
4
|
@@all = []
|
5
5
|
|
6
6
|
def initialize(book_info_hash)
|
7
|
-
book_info_hash.
|
7
|
+
book_info_hash.map { |key, val|
|
8
8
|
send "#{key}=", val
|
9
9
|
}
|
10
10
|
@@all << self
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.create_from_collection(book_info_array)
|
14
|
-
book_info_array.
|
14
|
+
book_info_array.map { |book_info_hash|
|
15
15
|
self.new(book_info_hash)
|
16
16
|
}
|
17
17
|
end
|
data/lib/libri/books.rb
CHANGED
@@ -4,14 +4,14 @@ class Libri::Books
|
|
4
4
|
@@all = []
|
5
5
|
|
6
6
|
def initialize(books_hash)
|
7
|
-
books_hash.
|
7
|
+
books_hash.map { |key, val|
|
8
8
|
send "#{key}=", val
|
9
9
|
}
|
10
10
|
@@all << self
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.create_from_collection(books_array)
|
14
|
-
books_array.
|
14
|
+
books_array.map { |books_hash|
|
15
15
|
self.new(books_hash)
|
16
16
|
}
|
17
17
|
end
|
data/lib/libri/cli.rb
CHANGED
@@ -3,37 +3,12 @@ class Libri::CLI
|
|
3
3
|
attr_accessor :award, :awards_array, :books_array, :book_info_hash, :quotes_array, :title_by_author
|
4
4
|
|
5
5
|
LINE = "----------------------------------------------------------"
|
6
|
-
SPACE = " "
|
7
|
-
STRING = <<-EOS
|
8
|
-
. .
|
9
|
-
!!!!!!!
|
10
|
-
..'''::::.. . [[[|]]] .
|
11
|
-
.::' ``::.. !!!!!!!!|--_--|!!!!!
|
12
|
-
'...::' `'':::. [[[[[[[[\\_(X)_/]]]]]
|
13
|
-
. . |=| ._/-__-__\\===========/-__\\_
|
14
|
-
!!!!!!!!!\\========[ /]]|[[\\ ]=====/
|
15
|
-
/_-_-| | |-_--|=| | | ||=|_|_|=||"|==|
|
16
|
-
/-__--|_|_|_-_-| |_|_|=||______=||_| =|
|
17
|
-
/-----------------------\\===========/-----/
|
18
|
-
^^^\\^^^^^^^^^^^^^^^^^^^^^^[[|]]|[[|]]=====/
|
19
|
-
|.' ..==::'"'::==.. '.[ /~~~~~\\ ]]]]]]]
|
20
|
-
| .'=[[[|]]|[[|]]]=`._||== = || =\\ ]
|
21
|
-
||= == ||:^s^:|| = == ||=| | | || |=||
|
22
|
-
_||_ = =||o---.|| = ==_||_= == =||==_||_
|
23
|
-
\\__/= = ||: :||= == \\__/[][][][][]\\__/
|
24
|
-
[||]= ==||:___:|| = = [||]\\//\\//\\[||]
|
25
|
-
} {---'"'-----'"'- --} {//\\//\\//} {
|
26
|
-
____[==]__________________[==]\\//\\//\\[==]_____
|
27
|
-
|`|~~~~|================|~~~~|~~~~~~~~|~~~~||
|
28
|
-
jgs|^| ^ |================|^ | ^ ^^ ^ | ^ ||
|
29
|
-
EOS
|
30
6
|
|
31
7
|
def call
|
32
|
-
puts
|
33
|
-
puts
|
34
|
-
puts "Welcome to Libri. I'm the Raven, your guide in this chamber full of literary wonders.".blue
|
8
|
+
puts "Welcome to Libri.".blue
|
9
|
+
puts "I'm the Raven, your guide in this chamber full of literary wonders.".blue
|
35
10
|
puts "Below are some of the most prized literary awards of our time.".blue
|
36
|
-
puts "Come freely. This will take a few moments
|
11
|
+
puts "Come freely. This will take a few moments...".blue
|
37
12
|
puts LINE
|
38
13
|
make_awards
|
39
14
|
list_awards
|
@@ -42,7 +17,7 @@ class Libri::CLI
|
|
42
17
|
end
|
43
18
|
|
44
19
|
def make_awards
|
45
|
-
@awards_array = Scraper.scrape_barnes_noble
|
20
|
+
@awards_array = Libri::Scraper.new.scrape_barnes_noble
|
46
21
|
Libri::Awards.create_from_collection(awards_array)
|
47
22
|
end
|
48
23
|
|
@@ -58,7 +33,7 @@ class Libri::CLI
|
|
58
33
|
end
|
59
34
|
|
60
35
|
def make_books(award)
|
61
|
-
@books_array = Scraper.scrape_award(award)
|
36
|
+
@books_array = Libri::Scraper.new.scrape_award(award)
|
62
37
|
Libri::Books.create_from_collection(books_array)
|
63
38
|
end
|
64
39
|
|
@@ -75,10 +50,10 @@ class Libri::CLI
|
|
75
50
|
end
|
76
51
|
|
77
52
|
def list_details(book)
|
78
|
-
@book_info_hash = Scraper.scrape_book(book)
|
53
|
+
@book_info_hash = Libri::Scraper.new.scrape_book(book)
|
79
54
|
|
80
55
|
@book_info_hash.each { |key, val|
|
81
|
-
puts
|
56
|
+
puts
|
82
57
|
puts "#{key}".upcase.red
|
83
58
|
puts LINE
|
84
59
|
puts "#{val}"
|
@@ -86,21 +61,21 @@ class Libri::CLI
|
|
86
61
|
end
|
87
62
|
|
88
63
|
def random_quote
|
89
|
-
@quotes_array = Scraper.scrape_quote
|
64
|
+
@quotes_array = Libri::Scraper.new.scrape_quote
|
90
65
|
Libri::Quote.create_from_collection(quotes_array)
|
91
66
|
|
92
67
|
random = @quotes_array.sample
|
93
68
|
random.each { |key, val|
|
94
|
-
puts
|
69
|
+
puts
|
95
70
|
puts "#{val}"
|
96
71
|
}
|
97
|
-
puts
|
72
|
+
puts
|
98
73
|
end
|
99
74
|
|
100
75
|
def menu_awards
|
101
76
|
input = STDIN.gets.strip.downcase
|
102
77
|
|
103
|
-
if input.to_i.between?(1,
|
78
|
+
if input.to_i.between?(1,Libri::Awards.all.size)
|
104
79
|
award = @awards_array[input.to_i - 1]
|
105
80
|
Libri::Books.all.clear
|
106
81
|
make_books(award)
|
@@ -126,8 +101,8 @@ class Libri::CLI
|
|
126
101
|
book = @books_array[input.to_i - 1]
|
127
102
|
list_details(book)
|
128
103
|
puts LINE
|
129
|
-
puts "
|
130
|
-
puts "
|
104
|
+
puts "To list the books of the same award again, type books".blue
|
105
|
+
puts "To list all the awards again, type awards".blue
|
131
106
|
puts LINE
|
132
107
|
menu_books(award)
|
133
108
|
elsif input == "nevermore"
|
data/lib/libri/quote.rb
CHANGED
@@ -4,14 +4,14 @@ class Libri::Quote
|
|
4
4
|
@@all = []
|
5
5
|
|
6
6
|
def initialize(quote_hash)
|
7
|
-
quote_hash.
|
7
|
+
quote_hash.map { |key, val|
|
8
8
|
send "#{key}=", val
|
9
9
|
}
|
10
10
|
@@all << self
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.create_from_collection(quotes_array)
|
14
|
-
quotes_array.
|
14
|
+
quotes_array.map { |quote_hash|
|
15
15
|
self.new(quote_hash)
|
16
16
|
}
|
17
17
|
end
|
data/lib/libri/scraper.rb
CHANGED
@@ -1,88 +1,65 @@
|
|
1
|
-
class Scraper
|
1
|
+
class Libri::Scraper
|
2
2
|
|
3
3
|
attr_accessor :url, :award, :book
|
4
4
|
|
5
|
-
def
|
5
|
+
def scrape_barnes_noble
|
6
6
|
html = "https://www.barnesandnoble.com/b/books/awards/_/N-8q8Z1d6q?showMoreIds=10008"
|
7
7
|
awards_page = Nokogiri::HTML(open(html))
|
8
8
|
|
9
|
-
awards_array = []
|
10
9
|
awards = {}
|
11
10
|
|
12
|
-
|
11
|
+
# Chosen .take(28) because without it, our awards list will include a 'Show Less'
|
12
|
+
awards_array = awards_page.css("ul#sidebar-section-0 li a").take(28).map { |award|
|
13
13
|
awards = {
|
14
14
|
:name => award.text.chomp,
|
15
15
|
:url => "https://www.barnesandnoble.com" + award.attribute("href").value
|
16
16
|
}
|
17
|
-
awards_array << awards
|
18
17
|
}
|
19
|
-
awards_array
|
20
18
|
end
|
21
19
|
|
22
|
-
def
|
20
|
+
def scrape_award(award)
|
23
21
|
html = award[:url]
|
24
22
|
books_page = Nokogiri::HTML(open(html))
|
25
23
|
|
26
|
-
books_array = []
|
27
24
|
books = {}
|
28
25
|
|
29
|
-
books_page.css("div.product-shelf-info").take(20).
|
26
|
+
books_array = books_page.css("div.product-shelf-info").take(20).map { |book|
|
30
27
|
books = {
|
31
28
|
:title => book.css("div.product-shelf-title").text.strip,
|
32
29
|
:author => book.css("div.product-shelf-author").text.strip,
|
33
30
|
:url => "https://www.barnesandnoble.com" + book.css("a").attribute("href").value
|
34
31
|
}
|
35
|
-
|
36
|
-
books_array << books
|
37
|
-
}
|
38
|
-
|
39
|
-
books_array.uniq
|
32
|
+
}.uniq
|
40
33
|
end
|
41
34
|
|
42
|
-
def
|
35
|
+
def scrape_book(book)
|
43
36
|
html = book[:url]
|
44
37
|
book_page = Nokogiri::HTML(open(html))
|
45
38
|
info_section = book_page.css("div.tabpanel")
|
46
39
|
|
47
|
-
# related_books_hash = {}
|
48
|
-
|
49
40
|
book_info_hash = {
|
50
41
|
:title_by_author => info_section.css("div#productInfoOverview div.mb-m").text,
|
51
42
|
:blurbs_and_plot => info_section.css("div#productInfoOverview p").map(&:text).join("\n").strip,
|
52
43
|
:about_author => info_section.css("div#MeetTheAuthor div.text--medium").text.strip,
|
53
|
-
:excerpt => info_section.xpath("//div[@class='read-an-excerpt']/p[not(@class) and position()<
|
54
|
-
# :related_books => book_page.css("div.product-shelf-info").each { |book|
|
55
|
-
# related_books_hash = {
|
56
|
-
# :title => book.css("div.product-shelf-title").text.strip,
|
57
|
-
# :author => book.css("div.product-shelf-author").text.strip,
|
58
|
-
# :url => "https://www.barnesandnoble.com" + book.css("a").attribute("href").value
|
59
|
-
# }
|
60
|
-
# },
|
44
|
+
:excerpt => info_section.xpath("//div[@class='read-an-excerpt']/p[not(@class) and position()<3]").map(&:text).join("\n"),
|
61
45
|
:availability => book_page.css("button#pdp-marketplace-btn").text.chomp,
|
62
46
|
:url => book[:url]
|
63
|
-
}
|
64
|
-
|
65
|
-
book_info_hash.delete_if { |key, val| val.to_s.strip.empty? }
|
66
|
-
|
47
|
+
}.delete_if { |key, val| val.to_s.strip.empty? }
|
67
48
|
end
|
68
49
|
|
69
|
-
def
|
50
|
+
def scrape_quote
|
70
51
|
html = "https://www.goodreads.com/quotes/tag/books"
|
71
52
|
quotes_page = Nokogiri::HTML(open(html))
|
72
53
|
quote_section = quotes_page.css("div.quote")
|
73
54
|
|
74
|
-
quotes_array = []
|
75
55
|
quote_hash = {}
|
76
56
|
|
77
|
-
quote_section.
|
57
|
+
quotes_array = quote_section.map { |quote|
|
78
58
|
quote_hash = {
|
79
59
|
:quote => quote.css("div.quoteText").first.text.scan(/(“.+”)/).join(""),
|
80
60
|
:author => quote.css("div.quoteText a").first.text
|
81
61
|
}
|
82
|
-
|
83
|
-
quotes_array << quote_hash
|
84
62
|
}
|
85
|
-
quotes_array
|
86
63
|
end
|
87
64
|
|
88
65
|
end
|
data/lib/libri/version.rb
CHANGED
data/libri-0.2.4.gem
ADDED
Binary file
|
data/libri.gemspec
CHANGED
@@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
|
|
36
36
|
spec.add_development_dependency "rake", "~> 10.0"
|
37
37
|
spec.add_development_dependency "rspec", "~> 3.0"
|
38
38
|
spec.add_development_dependency "gem-release"
|
39
|
+
spec.add_development_dependency "pry"
|
39
40
|
spec.add_dependency "nokogiri", "~> 1.8.3"
|
40
41
|
spec.add_dependency "colorize"
|
41
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libri
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jouissances
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: nokogiri
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -129,6 +143,7 @@ files:
|
|
129
143
|
- lib/libri/version.rb
|
130
144
|
- libri-0.2.2.gem
|
131
145
|
- libri-0.2.3.gem
|
146
|
+
- libri-0.2.4.gem
|
132
147
|
- libri.gemspec
|
133
148
|
- spec.md
|
134
149
|
homepage: https://rubygems.org
|