box-office-cli 0.1.2 → 0.1.3
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/box_office/cli.rb +21 -30
- data/lib/box_office/movie.rb +23 -6
- data/lib/box_office/scraper.rb +23 -34
- data/lib/box_office/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8cac9d25c7c1a316f2ba5fd7c905988c4f181b06f41b1e6b3ca342ac96561b84
|
4
|
+
data.tar.gz: 0761fb9cab67eeec86ef98d0c68c9604488d446363abb331c725858be02b1436
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79d3f5a870f219c8d27141736ead407d562cbaec8b19e78ed51e5d8e0793a65a27e4461e95ddb30c02f5aea5e8c4c8c69664e0823bbf58aa09b33889ff65921d
|
7
|
+
data.tar.gz: 06f7b7bd1184b9c32246cbcb5c31f8bddae8f892bab2c3c08ae53c9e326e82d631287c2684ac067cd1b87e507c93cd15afa0818994e91d2fd841e8fad42acb50
|
data/lib/box_office/cli.rb
CHANGED
@@ -14,44 +14,23 @@ class BoxOffice::CLI
|
|
14
14
|
def list_movies
|
15
15
|
puts "---"
|
16
16
|
puts "Last Weekend's Box Office:".colorize(:red)
|
17
|
-
|
18
|
-
puts "#{i + 1}.".colorize(:blue) + " #{movie}, #{earnings}"
|
17
|
+
BoxOffice::Movie.all.each_with_index do |movie, i|
|
18
|
+
puts "#{i + 1}.".colorize(:blue) + " #{movie.title}, #{movie.earnings}"
|
19
19
|
end
|
20
20
|
puts "---"
|
21
21
|
end
|
22
22
|
|
23
|
-
def add_attributes_to_movie(user_input)
|
24
|
-
movie = BoxOffice::Movie.all[user_input]
|
25
|
-
attributes = BoxOffice::Scraper.scrape_movie_page(user_input)
|
26
|
-
movie.add_movie_attributes(attributes)
|
27
|
-
end
|
28
|
-
|
29
|
-
def display_movie_info(user_input)
|
30
|
-
movie = BoxOffice::Movie.all[user_input]
|
31
|
-
puts "---"
|
32
|
-
puts "#{movie.title}".colorize(:red)
|
33
|
-
puts "#{movie.synopsis}" if movie.synopsis != ""
|
34
|
-
puts "" if movie.synopsis != ""
|
35
|
-
puts "Genres:".colorize(:blue) + " #{movie.genres}" if !movie.genres.nil?
|
36
|
-
puts "Rating:".colorize(:blue) + " #{movie.rating}" if !movie.rating.nil?
|
37
|
-
puts "Studio:".colorize(:blue) + " #{movie.studio}" if !movie.studio.nil?
|
38
|
-
puts "Director:".colorize(:blue) + " #{movie.director}" if !movie.director.nil?
|
39
|
-
puts "Writers:".colorize(:blue) + " #{movie.writers}" if !movie.writers.nil?
|
40
|
-
puts "Cast:".colorize(:blue) + " #{movie.cast}" if movie.cast != ""
|
41
|
-
puts "Release Date:".colorize(:blue) + " #{movie.release_date}" if !movie.release_date.nil?
|
42
|
-
puts "Runtime:".colorize(:blue) + " #{movie.runtime}" if !movie.runtime.nil?
|
43
|
-
puts "Critic Score:".colorize(:blue) + " #{movie.critic_score}"
|
44
|
-
puts "Audience Score:".colorize(:blue) + " #{movie.audience_score}"
|
45
|
-
puts "---"
|
46
|
-
end
|
47
|
-
|
48
23
|
def menu
|
49
24
|
input = nil
|
50
25
|
until input == "exit"
|
51
|
-
puts "
|
26
|
+
puts "What do you want to do?".colorize(:green)
|
27
|
+
puts "* Enter ".colorize(:green) + "movie number".colorize(:blue) + " to learn more about the movie".colorize(:green)
|
28
|
+
puts "* Type '".colorize(:green) + "list".colorize(:blue) + "' to see the list again".colorize(:green)
|
29
|
+
puts "* Type '".colorize(:green) + "exit".colorize(:blue) + "' to leave the app".colorize(:green)
|
30
|
+
puts "---"
|
52
31
|
input = gets.strip.downcase
|
53
32
|
if input.to_i.between?(1, BoxOffice::Movie.all.length)
|
54
|
-
add_attributes_to_movie(input.to_i - 1)
|
33
|
+
add_attributes_to_movie(input.to_i - 1) if BoxOffice::Movie.all[input.to_i - 1].rating.nil? # Only scrapes webpage if attributes are 'nil' to prevent scraping multiple times
|
55
34
|
display_movie_info(input.to_i - 1)
|
56
35
|
elsif input == "list"
|
57
36
|
list_movies
|
@@ -61,7 +40,19 @@ class BoxOffice::CLI
|
|
61
40
|
end
|
62
41
|
end
|
63
42
|
|
43
|
+
def add_attributes_to_movie(user_input)
|
44
|
+
movie = BoxOffice::Movie.all[user_input]
|
45
|
+
attributes = BoxOffice::Scraper.scrape_movie_page(user_input)
|
46
|
+
movie.add_movie_attributes(attributes)
|
47
|
+
end
|
48
|
+
|
49
|
+
def display_movie_info(user_input)
|
50
|
+
movie = BoxOffice::Movie.all[user_input]
|
51
|
+
movie.print_info
|
52
|
+
puts "---"
|
53
|
+
end
|
54
|
+
|
64
55
|
def goodbye
|
65
|
-
puts "Peace out homie!".colorize(:
|
56
|
+
puts "Peace out homie!".colorize(:cyan) + " <3".colorize(:light_red)
|
66
57
|
end
|
67
58
|
end
|
data/lib/box_office/movie.rb
CHANGED
@@ -1,18 +1,35 @@
|
|
1
1
|
class BoxOffice::Movie
|
2
|
-
attr_accessor :title, :
|
2
|
+
attr_accessor :title, :link, :earnings, :synopsis, :rating, :genres, :director,
|
3
|
+
:writers, :cast, :critic_score, :audience_score, :runtime, :studio, :release_date
|
4
|
+
|
3
5
|
@@all = []
|
4
6
|
|
5
|
-
def initialize
|
6
|
-
@title = title
|
7
|
+
def initialize
|
7
8
|
@@all << self
|
8
9
|
end
|
9
10
|
|
10
|
-
def add_movie_attributes(
|
11
|
-
|
12
|
-
self.send("#{
|
11
|
+
def add_movie_attributes(attributes_hash)
|
12
|
+
attributes_hash.each do |attr, value|
|
13
|
+
self.send("#{attr}=", value)
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
17
|
+
def print_info
|
18
|
+
puts "#{self.title}".colorize(:red)
|
19
|
+
puts "#{self.synopsis}" if self.synopsis != ""
|
20
|
+
puts "" if self.synopsis != ""
|
21
|
+
puts "Genres:".colorize(:blue) + " #{self.genres}" if !self.genres.nil?
|
22
|
+
puts "Rating:".colorize(:blue) + " #{self.rating}" if !self.rating.nil?
|
23
|
+
puts "Studio:".colorize(:blue) + " #{self.studio}" if !self.studio.nil?
|
24
|
+
puts "Director:".colorize(:blue) + " #{self.director}" if !self.director.nil?
|
25
|
+
puts "Writers:".colorize(:blue) + " #{self.writers}" if !self.writers.nil?
|
26
|
+
puts "Main Cast:".colorize(:blue) + " #{self.cast}" if self.cast != ""
|
27
|
+
puts "Release Date:".colorize(:blue) + " #{self.release_date}" if !self.release_date.nil?
|
28
|
+
puts "Runtime:".colorize(:blue) + " #{self.runtime}" if !self.runtime.nil?
|
29
|
+
puts "Critic Score:".colorize(:blue) + " #{self.critic_score}"
|
30
|
+
puts "Audience Score:".colorize(:blue) + " #{self.audience_score}"
|
31
|
+
end
|
32
|
+
|
16
33
|
def self.all
|
17
34
|
@@all
|
18
35
|
end
|
data/lib/box_office/scraper.rb
CHANGED
@@ -1,27 +1,18 @@
|
|
1
1
|
class BoxOffice::Scraper
|
2
|
-
|
3
|
-
|
4
|
-
def self.scrape_movie_list # Creates Movie objects and creates hash with movie titles and earnings from scraped website
|
2
|
+
def self.scrape_movie_list # Scrapes website and creates Movie objects
|
5
3
|
movie_list = Nokogiri::HTML(open("https://www.rottentomatoes.com/browse/box-office/?rank_id=0&country=us"))
|
6
|
-
titles = []
|
7
|
-
earnings = []
|
8
|
-
|
9
|
-
movie_list.css("table td.left a").each do |title|
|
10
|
-
@@movie_links << title.attr("href")
|
11
|
-
movie = BoxOffice::Movie.new(title.text)
|
12
|
-
titles << movie.title
|
13
|
-
end
|
14
4
|
|
15
|
-
movie_list.css("table
|
16
|
-
|
5
|
+
movie_list.css("table.center.table tr[itemprop='itemListElement']").each do |row|
|
6
|
+
movie = BoxOffice::Movie.new
|
7
|
+
movie.title = row.css("td.left a").text.strip
|
8
|
+
movie.link = row.css("td.left a").attr("href").text.strip
|
9
|
+
movie.earnings = row.css("td[7]").text.strip
|
17
10
|
end
|
18
|
-
|
19
|
-
[titles, earnings].transpose.to_h
|
20
11
|
end
|
21
12
|
|
22
|
-
def self.scrape_movie_page(index) # Scrapes movie webpage and creates hash of movie
|
23
|
-
|
24
|
-
movie_page = Nokogiri::HTML(open("https://www.rottentomatoes.com/#{
|
13
|
+
def self.scrape_movie_page(index) # Scrapes movie webpage and creates hash of movie attributes
|
14
|
+
attributes = {}
|
15
|
+
movie_page = Nokogiri::HTML(open("https://www.rottentomatoes.com/#{BoxOffice::Movie.all[index].link}"))
|
25
16
|
|
26
17
|
# Scraping synopsis and cast
|
27
18
|
movie_synopsis = movie_page.css("div#movieSynopsis").text.strip
|
@@ -40,41 +31,39 @@ class BoxOffice::Scraper
|
|
40
31
|
movie_audience_score = movie_page.css("div.audience-score.meter").text.split[0]
|
41
32
|
end
|
42
33
|
|
43
|
-
# Scraping basic movie info and storing it
|
34
|
+
# Scraping basic movie info and storing it in a hash
|
44
35
|
info_keys = []
|
45
36
|
info_values = []
|
46
|
-
|
47
37
|
movie_page.css("ul.content-meta.info div.meta-label.subtle").each { |key| info_keys << key.text.strip }
|
48
38
|
movie_page.css("ul.content-meta.info div.meta-value").each { |value| info_values << value.text.gsub(/\n\s*/, "").strip }
|
49
|
-
|
50
39
|
info_hash = [info_keys, info_values].transpose.to_h
|
51
40
|
|
52
|
-
# Combining all scraped info into one hash called '
|
41
|
+
# Combining all scraped info into one hash called 'attributes'
|
53
42
|
info_hash.each do |key, value|
|
54
43
|
case key
|
55
44
|
when "Rating:"
|
56
|
-
|
45
|
+
attributes[:rating] = value
|
57
46
|
when "Genre:"
|
58
|
-
|
47
|
+
attributes[:genres] = value
|
59
48
|
when "Directed By:"
|
60
|
-
|
49
|
+
attributes[:director] = value
|
61
50
|
when "Written By:"
|
62
|
-
|
51
|
+
attributes[:writers] = value
|
63
52
|
when "In Theaters:"
|
64
|
-
|
53
|
+
attributes[:release_date] = value
|
65
54
|
when "Runtime:"
|
66
|
-
|
55
|
+
attributes[:runtime] = value
|
67
56
|
when "Studio:"
|
68
|
-
|
57
|
+
attributes[:studio] = value
|
69
58
|
end
|
70
59
|
end
|
71
60
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
61
|
+
attributes[:synopsis] = movie_synopsis
|
62
|
+
attributes[:critic_score] = movie_critic_score
|
63
|
+
attributes[:audience_score] = movie_audience_score
|
64
|
+
attributes[:cast] = movie_cast
|
76
65
|
|
77
|
-
|
66
|
+
attributes
|
78
67
|
end
|
79
68
|
|
80
69
|
end
|
data/lib/box_office/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: box-office-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Mei
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -131,5 +131,5 @@ rubyforge_project:
|
|
131
131
|
rubygems_version: 2.7.7
|
132
132
|
signing_key:
|
133
133
|
specification_version: 4
|
134
|
-
summary: A gem that provides information on last weekend's movie box office.
|
134
|
+
summary: A simple gem that provides information on last weekend's movie box office.
|
135
135
|
test_files: []
|