bookworm_best_sellers 1.0.0 → 1.0.1
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 +4 -4
- data/bookworm_best_sellers.gemspec +3 -3
- data/lib/bookworm_best_sellers.rb +1 -0
- data/lib/bookworm_best_sellers/book.rb +8 -50
- data/lib/bookworm_best_sellers/cli.rb +1 -1
- data/lib/bookworm_best_sellers/scraper.rb +29 -0
- data/lib/bookworm_best_sellers/version.rb +1 -1
- metadata +15 -14
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1a6ba1ec3fc3c3f0cd3bc8ed1facc3686cdc8867
|
|
4
|
+
data.tar.gz: 202aa8c3fc4fac67aae17f71cca05dcbb597d336
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 00b8fa322022818f0e1cf01726462db6c1eb9db4d36f35b312039a2f34168516545e4a06f5375f346efdfd3ac0877a77036da83a5b3dd85eb33fee290c8cca92
|
|
7
|
+
data.tar.gz: 5ec2a2a256af13d0b5b8150991a1b4ddeb04a97ab0cd203772e7a904f1d661370c758ca502cb733de9c0ea19e4019cb0159569986e5d1094c47262d632b7813d
|
data/Gemfile.lock
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
bookworm_best_sellers (1.0.
|
|
5
|
-
nokogiri
|
|
4
|
+
bookworm_best_sellers (1.0.1)
|
|
5
|
+
nokogiri (~> 1.6.8)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
@@ -41,9 +41,9 @@ PLATFORMS
|
|
|
41
41
|
DEPENDENCIES
|
|
42
42
|
bookworm_best_sellers!
|
|
43
43
|
bundler (~> 1.10)
|
|
44
|
-
pry
|
|
44
|
+
pry (~> 0.10.3)
|
|
45
45
|
rake (~> 10.0)
|
|
46
|
-
rspec
|
|
46
|
+
rspec (~> 3.4.0)
|
|
47
47
|
|
|
48
48
|
BUNDLED WITH
|
|
49
49
|
1.12.5
|
|
@@ -23,8 +23,8 @@ Gem::Specification.new do |spec|
|
|
|
23
23
|
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.10"
|
|
25
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
|
26
|
-
spec.add_development_dependency "rspec"
|
|
27
|
-
spec.add_development_dependency "pry"
|
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.4"
|
|
27
|
+
spec.add_development_dependency "pry", "~> 0.10"
|
|
28
28
|
|
|
29
|
-
spec.add_dependency "nokogiri"
|
|
29
|
+
spec.add_dependency "nokogiri", "~> 1.6"
|
|
30
30
|
end
|
|
@@ -1,59 +1,17 @@
|
|
|
1
1
|
class BookwormBestSellers::Book
|
|
2
2
|
attr_accessor :title, :author, :description, :url
|
|
3
3
|
@@current_book_list = []
|
|
4
|
-
@@current_descriptions = []
|
|
5
|
-
@@doc = Nokogiri::HTML(open("http://www.barnesandnoble.com/b/the-new-york-times-bestsellers-hardcover-nonfiction/_/N-1p5q"))
|
|
6
4
|
|
|
7
|
-
def
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
def initialize(attributes = {})
|
|
6
|
+
@title = attributes[:title]
|
|
7
|
+
@author = attributes[:author]
|
|
8
|
+
@description = attributes[:description]
|
|
9
|
+
@url = attributes[:url]
|
|
10
|
+
@@current_book_list << self
|
|
13
11
|
end
|
|
14
12
|
|
|
15
|
-
def self.
|
|
16
|
-
|
|
17
|
-
self.scrape_titles.each do |ind_title|
|
|
18
|
-
if books.length < 10
|
|
19
|
-
book = self.new
|
|
20
|
-
book.title = ind_title
|
|
21
|
-
books << book
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
books.each.with_index(0) do |ind_book, i|
|
|
25
|
-
ind_book.author = self.scrape_authors[i]
|
|
26
|
-
end
|
|
27
|
-
books.each.with_index(0) do |ind_book, i|
|
|
28
|
-
ind_book.url = ["http://www.barnesandnoble.com",self.scrape_urls[i]].join()
|
|
29
|
-
end
|
|
30
|
-
books.each.with_index(0) do |ind_book, i|
|
|
31
|
-
ind_book.description = self.scrape_descriptions[i]
|
|
32
|
-
end
|
|
33
|
-
books
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def self.scrape_titles
|
|
37
|
-
@@doc.search("p.product-info-title").text.split("\n").reject { |item| item.nil? || item == "" }.map { |ind_title| ind_title[0...-13] }
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def self.scrape_authors
|
|
41
|
-
@@doc.search("span.contributor").to_s.split("/a").map! { |author| author[-25..-1] }.reject { |author| author.nil? || author == "" }.map! { |author| author.split(">")[1] }.map! { |ind_author| ind_author[0...-1] }
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def self.scrape_urls
|
|
45
|
-
[*0..9].map! { |index| @@doc.css("p.product-info-title a")[index]['href'].split(";")[0] }
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def self.scrape_descriptions
|
|
49
|
-
if @@current_descriptions == []
|
|
50
|
-
@@current_descriptions = [*0..9].map! do |i|
|
|
51
|
-
url = ["http://www.barnesandnoble.com",self.scrape_urls[i]].join()
|
|
52
|
-
Nokogiri::HTML(open(url)).css('div#productInfoOverview p').text.split("\n").reject { |item| item.nil? || item == "" }[0]
|
|
53
|
-
end
|
|
54
|
-
else
|
|
55
|
-
@@current_descriptions
|
|
56
|
-
end
|
|
13
|
+
def self.all
|
|
14
|
+
@@current_book_list
|
|
57
15
|
end
|
|
58
16
|
|
|
59
17
|
end
|
|
@@ -7,7 +7,7 @@ class BookwormBestSellers::CLI
|
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
def list_books
|
|
10
|
-
@books = BookwormBestSellers::
|
|
10
|
+
@books = BookwormBestSellers::Scraper.this_week
|
|
11
11
|
puts "\nBest Sellers - Week of #{current_week}\n\n"
|
|
12
12
|
@books.each.with_index(1) do |book, i|
|
|
13
13
|
puts "#{i}. #{book.title} - #{book.author}"
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
class BookwormBestSellers::Scraper
|
|
2
|
+
|
|
3
|
+
@@doc = Nokogiri::HTML(open("http://www.barnesandnoble.com/b/the-new-york-times-bestsellers-hardcover-nonfiction/_/N-1p5q"))
|
|
4
|
+
|
|
5
|
+
def self.this_week
|
|
6
|
+
if BookwormBestSellers::Book.all == []
|
|
7
|
+
self.scrape_books
|
|
8
|
+
BookwormBestSellers::Book.all
|
|
9
|
+
else
|
|
10
|
+
BookwormBestSellers::Book.all
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.scrape_books
|
|
15
|
+
titles = @@doc.search("p.product-info-title").text.split("\n").compact.reject { |i| i.empty? }.map { |i| i[0...-13] }
|
|
16
|
+
|
|
17
|
+
authors = @@doc.search("span.contributors").text.split(" by ").reject { |i| i.empty?}
|
|
18
|
+
|
|
19
|
+
urls = @@doc.css("p.product-info-title a").map { |i| i['href'].split(";")[0] }
|
|
20
|
+
|
|
21
|
+
descriptions = urls.map { |ind_url|
|
|
22
|
+
url = ["http://www.barnesandnoble.com",ind_url].join()
|
|
23
|
+
Nokogiri::HTML(open(url)).css('div#productInfoOverview p').text.split("\n").compact.reject { |i| i.empty? }[0] }
|
|
24
|
+
|
|
25
|
+
[*0..9].map! { |index|
|
|
26
|
+
BookwormBestSellers::Book.new(attributes = {title: titles[index], author: authors[index], url: urls[index], description: descriptions[index]}) }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bookworm_best_sellers
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- William Saxe
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-
|
|
11
|
+
date: 2016-10-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -42,44 +42,44 @@ dependencies:
|
|
|
42
42
|
name: rspec
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
|
-
- - "
|
|
45
|
+
- - "~>"
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: '
|
|
47
|
+
version: '3.4'
|
|
48
48
|
type: :development
|
|
49
49
|
prerelease: false
|
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
|
-
- - "
|
|
52
|
+
- - "~>"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: '
|
|
54
|
+
version: '3.4'
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
56
|
name: pry
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements:
|
|
59
|
-
- - "
|
|
59
|
+
- - "~>"
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '0'
|
|
61
|
+
version: '0.10'
|
|
62
62
|
type: :development
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
|
-
- - "
|
|
66
|
+
- - "~>"
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '0'
|
|
68
|
+
version: '0.10'
|
|
69
69
|
- !ruby/object:Gem::Dependency
|
|
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.6'
|
|
76
76
|
type: :runtime
|
|
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.6'
|
|
83
83
|
description: The Bookworm gem provides the current week's bestselling books in the
|
|
84
84
|
USA according to the New York Times. Best Selling Book list is live updated when
|
|
85
85
|
the gem is executed.
|
|
@@ -104,6 +104,7 @@ files:
|
|
|
104
104
|
- lib/bookworm_best_sellers.rb
|
|
105
105
|
- lib/bookworm_best_sellers/book.rb
|
|
106
106
|
- lib/bookworm_best_sellers/cli.rb
|
|
107
|
+
- lib/bookworm_best_sellers/scraper.rb
|
|
107
108
|
- lib/bookworm_best_sellers/version.rb
|
|
108
109
|
homepage: https://github.com/wsaxe/bookworm-best-sellers
|
|
109
110
|
licenses:
|