nyt-bestsellers 0.0.2 → 0.0.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/bin/nyt-bestsellers +1 -1
- data/lib/nytimes/book.rb +2 -2
- data/lib/nytimes/cli.rb +23 -24
- data/lib/nytimes/genre.rb +1 -1
- data/lib/nytimes/scraper.rb +5 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 364b65e29799c494484045f477d1fe2094d0f172
|
4
|
+
data.tar.gz: 4be1d126014b763428f274def89093b436dc2af1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad9c40794d6af2f71e94c51d4945b6c263090c965308f776a6e4d1edddea0f09ca9e3bf01146ae4a831cf63e69dfe6de5a36221ec739ce78e88eafafe86879d8
|
7
|
+
data.tar.gz: 951595ba0534a305b7480ff8c9bb67fdee9073e6a13670b71d0e2c6ea7e5f8c4921bfba8651c47f6600e55f5a6fe79e418988894d1fc455cf628821bf414f612
|
data/bin/nyt-bestsellers
CHANGED
data/lib/nytimes/book.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
class
|
1
|
+
class Book
|
2
2
|
|
3
3
|
attr_accessor :genre, :title, :author, :publisher, :wol, :summary
|
4
4
|
|
5
5
|
@@all = []
|
6
6
|
|
7
7
|
def initialize(genre=nil, title=nil, author=nil, publisher=nil, wol=nil, summary=nil)
|
8
|
-
@genre =
|
8
|
+
@genre = Genre.find_by_name(genre)
|
9
9
|
@genre.books << self if !wol.empty? || !summary.empty?
|
10
10
|
@title = title
|
11
11
|
@author = author
|
data/lib/nytimes/cli.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
class
|
1
|
+
class CLI
|
2
2
|
|
3
3
|
def call
|
4
|
-
|
5
|
-
|
4
|
+
Scraper.make_genres
|
5
|
+
Scraper.make_books
|
6
6
|
puts ""
|
7
7
|
puts "Welcome to the New York Times Bestsellers List".blue.bold
|
8
8
|
run
|
@@ -11,7 +11,7 @@ class NYTBestsellers::CLI
|
|
11
11
|
def run
|
12
12
|
puts "-------------------"
|
13
13
|
puts ""
|
14
|
-
puts "NYT Bestsellers - Week of #{
|
14
|
+
puts "NYT Bestsellers - Week of #{Scraper.get_date}".bold.blue
|
15
15
|
puts "(Lists are published early online.)".bold.blue
|
16
16
|
puts ""
|
17
17
|
puts "Here are the categories:"
|
@@ -34,17 +34,17 @@ class NYTBestsellers::CLI
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def genre_count
|
37
|
-
|
37
|
+
Genre.all.count
|
38
38
|
end
|
39
39
|
|
40
40
|
def display_genres
|
41
|
-
|
41
|
+
Genre.all.each_with_index do |genre, index|
|
42
42
|
puts "#{index+1} - #{genre.name}"
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
def genre_books(response)
|
47
|
-
genre =
|
47
|
+
genre = Genre.find_by_num(response)
|
48
48
|
puts ""
|
49
49
|
puts "****----#{genre.name.upcase}----****".blue.bold
|
50
50
|
puts ""
|
@@ -81,7 +81,7 @@ class NYTBestsellers::CLI
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def display_book_info(response, book_input)
|
84
|
-
genre =
|
84
|
+
genre = Genre.find_by_num(response)
|
85
85
|
|
86
86
|
genre.books.each_with_index do |book, index|
|
87
87
|
if book_input.to_i == index+1
|
@@ -95,25 +95,24 @@ class NYTBestsellers::CLI
|
|
95
95
|
puts "---------Summary---------".bold
|
96
96
|
puts "#{book.summary}"
|
97
97
|
puts ""
|
98
|
-
puts "Type" + " 'back'".light_red + "," + " 'menu',".light_red + " or" + " 'exit'".light_red + "."
|
99
|
-
puts ""
|
100
98
|
|
101
|
-
input =
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
elsif input == "exit"
|
106
|
-
puts "Goodbye!~".bold.red
|
99
|
+
input = ""
|
100
|
+
while input != "exit"
|
101
|
+
puts "Type" + " 'back'".light_red + "," + " 'menu',".light_red + " or" + " 'exit'".light_red + "."
|
102
|
+
input = gets.strip
|
107
103
|
puts ""
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
104
|
+
if input == "back"
|
105
|
+
genre_books(response)
|
106
|
+
elsif input == "menu"
|
107
|
+
run
|
108
|
+
puts ""
|
109
|
+
elsif input == "exit"
|
110
|
+
puts "Goodbye!~".bold.red
|
111
|
+
puts ""
|
112
|
+
exit
|
113
|
+
end #second if
|
114
|
+
end
|
115
115
|
end #first if
|
116
116
|
end #each
|
117
117
|
end
|
118
|
-
|
119
118
|
end
|
data/lib/nytimes/genre.rb
CHANGED
data/lib/nytimes/scraper.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
class
|
1
|
+
class Scraper
|
2
2
|
|
3
3
|
def self.get_page
|
4
4
|
agent = Mechanize.new
|
@@ -11,7 +11,7 @@ class NYTBestsellers::Scraper
|
|
11
11
|
|
12
12
|
def self.make_genres
|
13
13
|
scrape_genres.each do |category|
|
14
|
-
|
14
|
+
Genre.new(
|
15
15
|
category.css("a.subcategory-heading-link").text.strip,
|
16
16
|
"http://www.nytimes.com#{category.css("a").attr("href").text}"
|
17
17
|
)
|
@@ -20,7 +20,7 @@ class NYTBestsellers::Scraper
|
|
20
20
|
|
21
21
|
def self.get_genre_pages
|
22
22
|
agent = Mechanize.new
|
23
|
-
|
23
|
+
Genre.all.collect do |genre|
|
24
24
|
page = agent.get("#{genre.url}")
|
25
25
|
end
|
26
26
|
end
|
@@ -30,7 +30,7 @@ class NYTBestsellers::Scraper
|
|
30
30
|
books = page.css("div.book-body")
|
31
31
|
|
32
32
|
books.each do |book|
|
33
|
-
|
33
|
+
Book.new(
|
34
34
|
page.css("h1").text.split(/\s-\s/)[0].strip, #genre
|
35
35
|
book.css("h2.title").text.split.collect(&:capitalize).join(" "),
|
36
36
|
book.css("p.author").text.split.delete_if{|x| x == "by"}.join(" "),
|
@@ -44,6 +44,5 @@ class NYTBestsellers::Scraper
|
|
44
44
|
|
45
45
|
def self.get_date
|
46
46
|
get_page.css("div.date-range").text.strip
|
47
|
-
end
|
48
|
-
|
47
|
+
end
|
49
48
|
end
|