top_box 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6e0b9977e7c77bbd11f9ce4bed2f90474d09e31bd3767297927af68586d007ba
4
+ data.tar.gz: 4deae212e5f3e2a03b277863a87b16af453bf1c51299dbebd1fe5e7bca474fdf
5
+ SHA512:
6
+ metadata.gz: f0620e27f45834e9747d2c0c5c5d4d7e5fd013dffb7dd9298d174e12726697a170bee79f3e2a6911cf271bf24e3eeb0be2458d46c5f5cba71db83a15add71ba2
7
+ data.tar.gz: f11f72527ab14ce493e4e8111a4737edd105ffdad31cc2b72cde747ed693388b1108f7301febf4cb513c4782f0e84ab23505d4fe82e589932e1435f4ab7af4e1
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at 'jkam17@gmail.com'. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/jk-me/top_box_cli" }
4
+
5
+ # Specify your gem's dependencies in top_box.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 'Jenny Kam'
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # TopBox
2
+
3
+ This is a Ruby CLI application that allows the user to view summaries and critic reviews of current top box office films. Data provided by imdb.com.
4
+
5
+
6
+ ##Requirements
7
+
8
+ This app was built on ruby 2.3.3
9
+
10
+ ## Usage
11
+
12
+ Initialize application with command below, then follow on screen prompts.
13
+
14
+ $ bin/top_box
15
+
16
+ ## Blog
17
+
18
+ A blog post detailing notes on the creation of this app can be found here: http://jellyjen.com/top_box_cli
19
+
20
+ ## Contributing
21
+
22
+ Bug reports and pull requests are welcome on GitHub at https://github.com/'jk-me'/top_box. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
23
+
24
+ ## License
25
+
26
+ The app is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
27
+
28
+ ## Code of Conduct
29
+
30
+ Everyone interacting in the TopBox project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/'jk-me'/top_box/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "top_box"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/bin/top_box ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/top_box_env'
4
+
5
+ TopBox::CLI.new.call
@@ -0,0 +1,71 @@
1
+ class TopBox::CLI
2
+
3
+ def call
4
+ puts 'Current Top Box Office Movies by imdb.com'
5
+ TopBox::Movie.new_from_collection(Scraper.scrape_movie_list)
6
+ list_movies
7
+ menu
8
+ end
9
+
10
+ def list_movies
11
+ #parse array of movie objects to output list
12
+ TopBox::Movie.all.each do |m|
13
+ puts "#{m.num}. #{m.title}"
14
+ puts "Week #{m.weeks_in_theater}, Total gross: #{m.total_gross}"
15
+ puts '--------------'
16
+ end
17
+ end
18
+
19
+ def menu
20
+ #takes user input to provide more information
21
+ puts "Enter number of a movie from the list to view a plot summary, 'list' to see the list of movies again or 'exit' to quit"
22
+ x = gets.strip.downcase
23
+ num = x.to_i
24
+ if num > 0 and num < TopBox::Movie.all.length + 1
25
+ m = TopBox::Movie.all[num-1]
26
+ if !m.summary
27
+ m.get_movie_details
28
+ end
29
+
30
+ puts "---------"
31
+ puts "#{m.title}, #{m.runtime}"
32
+ puts "Metascore: #{m.metascore}/100"
33
+ puts "---------"
34
+ puts m.summary
35
+ puts "---------"
36
+ review_menu(m)
37
+ elsif x=='exit'
38
+ exit
39
+ elsif x=='list'
40
+ list_movies
41
+ menu
42
+ else
43
+ puts "invalid entry"
44
+ menu
45
+ end
46
+ end
47
+
48
+ def review_menu(m)
49
+ #asks if user would like to see reviews for specific movie
50
+ puts "Would you like to see some critic reviews from this movie? y/n"
51
+ x=gets.strip.downcase
52
+ if x=='y'
53
+ m.get_reviews
54
+ puts "--------------"
55
+ m.reviews.each{ |review|
56
+ puts "Score: #{review.score}/100"
57
+ if review.author==''
58
+ puts "From: #{review.publication}"
59
+ else
60
+ puts "From: #{review.publication}, by #{review.author}"
61
+ end
62
+ puts review.summary
63
+ puts "--------------"
64
+ }
65
+ menu
66
+ else x=='n'
67
+ menu
68
+ end
69
+ end
70
+
71
+ end
@@ -0,0 +1,46 @@
1
+ class TopBox::Movie
2
+ attr_accessor :title, :weeks_in_theater, :total_gross, :url, :summary, :metascore, :rating, :runtime, :review_url, :reviews
3
+ @@all=[]
4
+
5
+ def initialize(attribute_hash)
6
+ @title = attribute_hash[:title]
7
+ @weeks_in_theater = attribute_hash[:weeks_in_theater]
8
+ @total_gross = attribute_hash[:total_gross]
9
+ @url = attribute_hash[:url]
10
+ @reviews = []
11
+ @@all << self
12
+ end
13
+
14
+ def self.all
15
+ @@all
16
+ end
17
+
18
+ def num
19
+ @@all.index(self)+1
20
+ end
21
+
22
+ def self.new_from_collection(movies_attributes_array)
23
+ movies_attributes_array.each{ |x| TopBox::Movie.new(x) }
24
+ end
25
+
26
+ def get_movie_details
27
+ movie_page = Scraper.scrape_movie_page(@url) #'/title/tt3104988'
28
+
29
+ @summary = movie_page.css('.inline.canwrap span')[0].text.strip
30
+ @metascore = movie_page.css('.metacriticScore').text.strip
31
+ @rating = movie_page.css('.txt-block span')[0].text.capitalize
32
+ @runtime = movie_page.css('.txt-block time').text
33
+ @review_url = movie_page.css('.titleReviewBarSubItem a').attribute('href').value
34
+ end
35
+
36
+ def get_reviews
37
+ if @reviews == []
38
+ reviews_array = Scraper.scrape_review_page("#{@url}/#{@review_url}")
39
+ reviews_array.each do |x|
40
+ a = TopBox::Review.new(x)
41
+ @reviews << a
42
+ end
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,11 @@
1
+ class TopBox::Review
2
+ attr_accessor :score, :publication, :author, :summary
3
+
4
+ def initialize(attribute_hash)
5
+ @score = attribute_hash[:score]
6
+ @publication = attribute_hash[:publication]
7
+ @summary = attribute_hash[:summary]
8
+ @author = attribute_hash[:author]
9
+ end
10
+
11
+ end
@@ -0,0 +1,49 @@
1
+ class Scraper
2
+ def self.scrape_movie_list
3
+ doc = Nokogiri::HTML(open('https://www.imdb.com/chart/boxoffice/'))
4
+ titles = doc.css('tr .titleColumn').collect{|x| x.text.strip}
5
+ urls = doc.css('tr .titleColumn a').collect{|x| x.attribute('href').value[0,16]} #/title/tt3104988
6
+ weeks_in_theater = doc.css('.weeksColumn').collect{|x| x.text}
7
+ total_gross = doc.css('.ratingColumn .secondaryInfo').collect{|x| x.text}
8
+
9
+ movies_attributes=[]
10
+ i=0
11
+ while i<titles.length
12
+ att_hash={}
13
+ att_hash[:url] = urls[i]
14
+ att_hash[:title] = titles[i]
15
+ att_hash[:weeks_in_theater] = weeks_in_theater[i]
16
+ att_hash[:total_gross] = total_gross[i]
17
+ movies_attributes << att_hash
18
+ i+=1
19
+ end
20
+ movies_attributes
21
+ end
22
+
23
+ def self.scrape_movie_page( url ) #'/title/tt3104988'
24
+ doc = Nokogiri::HTML(open('https://www.imdb.com' + url))
25
+ end
26
+
27
+ def self.scrape_review_page( url ) #'/title/tt3104988/criticreviews?ref_=tt_ov_rt'
28
+ doc = Nokogiri::HTML(open('https://www.imdb.com/' + url))
29
+ scores = doc.css('.critscore').collect{|y| y.text.strip}
30
+ publications = doc.css('.review b span').collect{|y| y.text}
31
+ authors = doc.css('.review span span').collect{|y| y.text}
32
+ #some_reviews may not have authors listed
33
+ summarys = doc.css('.review div').collect{|y| y.text.strip}
34
+
35
+ review_attributes=[]
36
+ i=0
37
+ while i < scores.length
38
+ att_hash={}
39
+ att_hash[:score] = scores[i]
40
+ att_hash[:publication] = publications[i]
41
+ att_hash[:author] = authors[i]
42
+ att_hash[:summary] = summarys[i]
43
+ review_attributes << att_hash
44
+ i+=1
45
+ end
46
+ review_attributes
47
+ end
48
+
49
+ end
@@ -0,0 +1,4 @@
1
+ module TopBox
2
+ VERSION = "0.1.0"
3
+
4
+ end
@@ -0,0 +1,9 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+ require 'pry'
4
+
5
+ require_relative "top_box/version"
6
+ require_relative "top_box/cli"
7
+ require_relative "top_box/scraper"
8
+ require_relative "top_box/movie"
9
+ require_relative "top_box/review"
data/top_box.gemspec ADDED
@@ -0,0 +1,37 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "top_box/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "top_box"
8
+ spec.version = '0.1.0'
9
+ spec.authors = ["'Jenny Kam'"]
10
+ spec.email = ["'jkam17@gmail.com'"]
11
+
12
+ spec.summary = %q{Top grossing movies currently in theaters. }
13
+ spec.description = %q{Provides top box office movie summaries, and critic reviews from imdb.com}
14
+ spec.homepage = "https://github.com/jk-me/top_box_cli"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = 'http://mygemserver.com'
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against " \
23
+ # "public gem pushes."
24
+ # end
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
29
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
+ end
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ spec.add_development_dependency "bundler", "~> 1.16"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: top_box
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - "'Jenny Kam'"
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-10-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Provides top box office movie summaries, and critic reviews from imdb.com
42
+ email:
43
+ - "'jkam17@gmail.com'"
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - CODE_OF_CONDUCT.md
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/console
55
+ - bin/setup
56
+ - bin/top_box
57
+ - lib/top_box/cli.rb
58
+ - lib/top_box/movie.rb
59
+ - lib/top_box/review.rb
60
+ - lib/top_box/scraper.rb
61
+ - lib/top_box/version.rb
62
+ - lib/top_box_env.rb
63
+ - top_box.gemspec
64
+ homepage: https://github.com/jk-me/top_box_cli
65
+ licenses:
66
+ - MIT
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 2.7.8
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: Top grossing movies currently in theaters.
88
+ test_files: []