libri 0.2.5 → 0.2.6
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/Gemfile.lock +1 -1
- data/bin/libri +1 -1
- data/lib/libri/book.rb +2 -4
- data/lib/libri/cli.rb +47 -22
- data/lib/libri/scraper.rb +13 -4
- data/lib/libri/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 782b2654c1e29ecc95a7aeb3814742a392af702d1dc1c3b9b32e018739955175
|
4
|
+
data.tar.gz: 94cad793e55d7c9bb3bb9316146303fa74115e24fa3b3ccf9390a24c2879ae59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ee437d12e80c7702558e4ce7a28840bd87d2aed9841fdcb4821dfd7dbdd0a154fa5bc8deaffc1593417d81c453994a6ffbd60e8aa5d45c71a612dba3d31d2be
|
7
|
+
data.tar.gz: 738d081060d7654cf2c353ad862f3d9294811bb797418b32d0214fc7e5050be0268aa94fe416927b9a975267eaebb3e5589b053e64bc5c6a6d59af206f66a052
|
data/Gemfile.lock
CHANGED
data/bin/libri
CHANGED
data/lib/libri/book.rb
CHANGED
@@ -10,10 +10,8 @@ class Libri::Book
|
|
10
10
|
@@all << self
|
11
11
|
end
|
12
12
|
|
13
|
-
def self.create_from_collection(
|
14
|
-
|
15
|
-
self.new(book_info_hash)
|
16
|
-
}
|
13
|
+
def self.create_from_collection(book_info_hash)
|
14
|
+
self.new(book_info_hash)
|
17
15
|
end
|
18
16
|
|
19
17
|
def self.all
|
data/lib/libri/cli.rb
CHANGED
@@ -17,8 +17,7 @@ class Libri::CLI
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def make_awards
|
20
|
-
|
21
|
-
Libri::Awards.create_from_collection(awards_array)
|
20
|
+
Libri::Scraper.new.scrape_barnes_noble
|
22
21
|
end
|
23
22
|
|
24
23
|
def list_awards
|
@@ -33,8 +32,7 @@ class Libri::CLI
|
|
33
32
|
end
|
34
33
|
|
35
34
|
def make_books(award)
|
36
|
-
|
37
|
-
Libri::Books.create_from_collection(books_array)
|
35
|
+
Libri::Scraper.new.scrape_award(award)
|
38
36
|
end
|
39
37
|
|
40
38
|
def list_books(award)
|
@@ -50,33 +48,60 @@ class Libri::CLI
|
|
50
48
|
end
|
51
49
|
|
52
50
|
def list_details(book)
|
53
|
-
|
51
|
+
info = Libri::Scraper.new.scrape_book(book)
|
52
|
+
|
53
|
+
puts
|
54
|
+
puts "Title by Author".upcase.red
|
55
|
+
puts LINE
|
56
|
+
puts "#{info.title_by_author}"
|
57
|
+
puts
|
58
|
+
puts "Blurbs and Plot".upcase.red
|
59
|
+
puts LINE
|
60
|
+
puts "#{info.blurbs_and_plot}"
|
61
|
+
puts
|
62
|
+
puts "About the Author".upcase.red
|
63
|
+
puts LINE
|
64
|
+
puts "#{info.about_author}"
|
65
|
+
puts
|
66
|
+
puts "Availability".upcase.red
|
67
|
+
puts LINE
|
68
|
+
puts "#{info.availability}"
|
69
|
+
puts
|
70
|
+
puts "URL".upcase.red
|
71
|
+
puts LINE
|
72
|
+
puts "#{info.url}"
|
73
|
+
puts
|
54
74
|
|
55
|
-
|
56
|
-
puts
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
75
|
+
if !info.excerpt.nil?
|
76
|
+
puts "An excerpt of this book is available. Would you like to read it? (Yn)"
|
77
|
+
input = STDIN.gets.strip.downcase
|
78
|
+
if input == "y"
|
79
|
+
puts
|
80
|
+
puts "Excerpt".upcase.red
|
81
|
+
puts LINE
|
82
|
+
puts "#{info.excerpt.slice(1..1000)}..."
|
83
|
+
puts
|
84
|
+
else
|
85
|
+
menu_books(award)
|
86
|
+
end
|
87
|
+
end
|
61
88
|
end
|
62
89
|
|
63
90
|
def random_quote
|
64
|
-
|
65
|
-
Libri::Quote.create_from_collection(quotes_array)
|
91
|
+
quote = Libri::Scraper.new.scrape_quote.sample
|
66
92
|
|
67
|
-
|
68
|
-
|
69
|
-
puts
|
70
|
-
puts "#{val}"
|
71
|
-
}
|
93
|
+
puts
|
94
|
+
puts "#{quote.quote}"
|
72
95
|
puts
|
96
|
+
puts "#{quote.author}"
|
97
|
+
puts
|
73
98
|
end
|
74
99
|
|
75
100
|
def menu_awards
|
76
101
|
input = STDIN.gets.strip.downcase
|
77
102
|
|
78
103
|
if input.to_i.between?(1,Libri::Awards.all.size)
|
79
|
-
award =
|
104
|
+
award = Libri::Awards.all[input.to_i - 1]
|
80
105
|
Libri::Books.all.clear
|
81
106
|
make_books(award)
|
82
107
|
list_books(award)
|
@@ -97,14 +122,14 @@ class Libri::CLI
|
|
97
122
|
def menu_books(award)
|
98
123
|
input = STDIN.gets.strip.downcase
|
99
124
|
|
100
|
-
if input.to_i.between?(1,
|
101
|
-
book =
|
125
|
+
if input.to_i.between?(1,Libri::Books.all.size)
|
126
|
+
book = Libri::Books.all[input.to_i - 1]
|
102
127
|
list_details(book)
|
103
128
|
puts LINE
|
104
129
|
puts "To list the books of the same award again, type books".blue
|
105
130
|
puts "To list all the awards again, type awards".blue
|
106
131
|
puts LINE
|
107
|
-
menu_books(award)
|
132
|
+
menu_books(award)
|
108
133
|
elsif input == "nevermore"
|
109
134
|
puts LINE
|
110
135
|
random_quote
|
data/lib/libri/scraper.rb
CHANGED
@@ -15,10 +15,12 @@ class Libri::Scraper
|
|
15
15
|
:url => "https://www.barnesandnoble.com" + award.attribute("href").value
|
16
16
|
}
|
17
17
|
}
|
18
|
+
|
19
|
+
Libri::Awards.create_from_collection(awards_array)
|
18
20
|
end
|
19
21
|
|
20
22
|
def scrape_award(award)
|
21
|
-
html = award
|
23
|
+
html = award.url
|
22
24
|
books_page = Nokogiri::HTML(open(html))
|
23
25
|
|
24
26
|
books = {}
|
@@ -30,10 +32,12 @@ class Libri::Scraper
|
|
30
32
|
:url => "https://www.barnesandnoble.com" + book.css("a").attribute("href").value
|
31
33
|
}
|
32
34
|
}.uniq
|
35
|
+
|
36
|
+
Libri::Books.create_from_collection(books_array)
|
33
37
|
end
|
34
38
|
|
35
39
|
def scrape_book(book)
|
36
|
-
html = book
|
40
|
+
html = book.url
|
37
41
|
book_page = Nokogiri::HTML(open(html))
|
38
42
|
info_section = book_page.css("div.tabpanel")
|
39
43
|
|
@@ -41,10 +45,13 @@ class Libri::Scraper
|
|
41
45
|
:title_by_author => info_section.css("div#productInfoOverview div.mb-m").text,
|
42
46
|
:blurbs_and_plot => info_section.css("div#productInfoOverview p").map(&:text).join("\n").strip,
|
43
47
|
:about_author => info_section.css("div#MeetTheAuthor div.text--medium").text.strip,
|
44
|
-
:excerpt => info_section.
|
48
|
+
:excerpt => info_section.css("div.read-an-excerpt p").text,
|
49
|
+
# info_section.xpath("//div[@class='read-an-excerpt']/p[not(@class) and position()<3]").map(&:text).join("\n"),
|
45
50
|
:availability => book_page.css("button#pdp-marketplace-btn").text.chomp,
|
46
|
-
:url => book
|
51
|
+
:url => book.url
|
47
52
|
}.delete_if { |key, val| val.to_s.strip.empty? }
|
53
|
+
|
54
|
+
Libri::Book.create_from_collection(book_info_hash)
|
48
55
|
end
|
49
56
|
|
50
57
|
def scrape_quote
|
@@ -60,6 +67,8 @@ class Libri::Scraper
|
|
60
67
|
:author => quote.css("div.quoteText a").first.text
|
61
68
|
}
|
62
69
|
}
|
70
|
+
|
71
|
+
Libri::Quote.create_from_collection(quotes_array)
|
63
72
|
end
|
64
73
|
|
65
74
|
end
|
data/lib/libri/version.rb
CHANGED