rotten-tomatoes 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 atom smith
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = rotten-tomatoes
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 atom smith. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "rotten-tomatoes"
8
+ gem.summary = 'Fetch information regarding movies from rottentomatoes.com'
9
+ gem.description = 'Allows you to search and get information about movies from rottentomatoes.com. Organizes returned information into easy to access attributes.'
10
+ gem.email = "re5etsmyth@gmail.com"
11
+ gem.homepage = "http://github.com/re5et/rotten-tomatoes"
12
+ gem.authors = ["atom smith"]
13
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "rotten-tomatoes #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,187 @@
1
+ # A scraper to search for and fetch useful information
2
+ # about movies from rottentomatoes.com
3
+ #
4
+ # Author:: atom smith (http://twitter.com/re5et)
5
+ # Copyright:: Copyright (c) 2010 atom smith
6
+ # License:: Distributes under the same terms as Ruby
7
+
8
+ require 'rubygems'
9
+ require 'nokogiri'
10
+ require 'open-uri'
11
+
12
+ # Module to hold everything
13
+ module Rotten_tomatoes
14
+
15
+ Base_url = 'http://www.rottentomatoes.com'
16
+ Search_url = Base_url + '/search/movie.php?searchby=movies&page=1&search='
17
+
18
+ # Create a new instance of Rotten_tomatoes::Movie with the
19
+ # rottentomatoes.com movie path as an argument
20
+ def self.get_info info_path
21
+ Movie.new info_path
22
+ end
23
+
24
+ # Search rottentomatoes.com for the movie you are looking for
25
+ # will return an array of movies for you to select from, each
26
+ # will contain the 'info_url' you need to us Rotten_tomatoes:get_info
27
+ def self.find_movie movie
28
+ movies = []
29
+ url = URI.parse(URI.encode(Search_url + movie))
30
+ results = Nokogiri::HTML(open(url))
31
+ results.css('#movie_search_main tr').each do |row|
32
+ movies.push({
33
+ :title => row.css('td:nth-of-type(3) p:first-of-type a').inner_text,
34
+ :plot => row.css('td:nth-of-type(3) p:nth-of-type(2)').inner_text.gsub(/\APlot:/, '').strip,
35
+ :year => row.css('.date').inner_text,
36
+ :director => row.css('td:nth-of-type(3) p:nth-of-type(3) a:first-of-type').inner_text,
37
+ :info_url => row.css('td:nth-of-type(3) p:first-of-type a').attr('href').value
38
+ })
39
+ end
40
+ return movies
41
+ end
42
+
43
+ # Uses Rotten_tomatoes::get_info to fetch info for the first
44
+ # search result found with Rotten_tomatoes::find_movie
45
+ def self.lucky_get_info movie
46
+ get_info find_movie(movie).first[:info_url]
47
+ end
48
+
49
+ # Rotten_tomatoes::Movie is a class that organizes the scraped
50
+ # information about the movie into easily accessible attribues.
51
+ class Movie
52
+
53
+ attr_reader :info_page, :title, :year, :people, :cast, :writers, :directors, :runtime, :rating, :tomatometer, :tomatometer_average_rating, :tomatometer_reviews_counted, :tomatometer_fresh, :tomatometer_rotten, :audience_rating, :number_of_ratings, :number_of_critic_reviews, :fresh_reviews, :rotten_reviews, :average_critic_rating, :genres, :release, :distributor
54
+
55
+ def initialize movie_url
56
+ @info_page = Nokogiri::HTML(open(URI.parse(Rotten_tomatoes::Base_url + movie_url)))
57
+ if @info_page
58
+ set_title_and_year
59
+ set_cast
60
+ set_writers
61
+ set_directors
62
+ set_people
63
+ set_runtime
64
+ set_rating
65
+ set_tomatometer
66
+ set_tomatometer_average_rating
67
+ set_tomatometer_reviews_counted
68
+ set_tomatometer_fresh_and_rotten
69
+ set_audience_rating
70
+ set_audience_average_rating
71
+ set_audience_number_of_ratings
72
+ set_genres
73
+ set_release
74
+ set_distributor
75
+ end
76
+ return self
77
+ end
78
+
79
+ private
80
+
81
+ def set_title_and_year
82
+ title_and_year = @info_page.css('h1.movie_title span').first.inner_html
83
+ match = title_and_year.match(/(.*)\((\d{4})\)/)
84
+ @title = match[1].strip
85
+ @year = match[2]
86
+ end
87
+
88
+ def set_cast
89
+ @cast = []
90
+ @info_page.css('#cast-info li').each do |person|
91
+ p person
92
+ @cast.push({
93
+ 'name' => person.css('a').inner_html,
94
+ 'info_path' => person.css('a').first['href'],
95
+ 'thumbnail' => person.css('img').first['src'],
96
+ 'characters'=> person.css('.characters').first.content.gsub(/\(\)/, '')
97
+ })
98
+ end
99
+ end
100
+
101
+ def set_writers
102
+ @writers = []
103
+ @info_page.css('.movie_info .right_col p:nth-child(3) a').each do |writer|
104
+ @writers.push({
105
+ 'name' => writer.inner_html,
106
+ 'info_path' => writer['href']
107
+ })
108
+ end
109
+ end
110
+
111
+ def set_directors
112
+ @directors = []
113
+ @info_page.css('.movie_info .right_col p:nth-child(2) a').each do |director|
114
+ @directors.push({
115
+ 'name' => director.inner_html,
116
+ 'info_path' => director['href']
117
+ })
118
+ end
119
+ end
120
+
121
+ def set_people
122
+ @people = { :cast => @cast, :writers => @writers, :directors => @directors }
123
+ end
124
+
125
+ def set_runtime
126
+ @runtime = @info_page.css('.movie_info .left_col p:nth-child(2) .content').first.inner_html
127
+ end
128
+
129
+ def set_rating
130
+ @rating = @info_page.css('.movie_info .left_col p:first-child .content span').text
131
+ end
132
+
133
+ def set_tomatometer
134
+ @tomatometer = @info_page.css('#all-critics-numbers #all-critics-meter').inner_html
135
+ end
136
+
137
+ def set_tomatometer_average_rating
138
+ @tomatometer_average_rating = @info_page.css('.critic_stats span:first-of-type').text.gsub(/\/.*/, '')
139
+ end
140
+
141
+ def set_tomatometer_reviews_counted
142
+ @tomatometer_reviews_counted = @info_page.css('.critic_stats span:nth-of-type(2)').text
143
+ end
144
+
145
+ def set_tomatometer_fresh_and_rotten
146
+ matches = @info_page.css('#all-critics-numbers .critic_stats').text.scan /Fresh:\s(\d+)\s|\sRotten:\s(\d)+/
147
+ @tomatometer_fresh = matches[0][0]
148
+ @tomatometer_rotten = matches[1][1]
149
+ end
150
+
151
+ def set_audience_rating
152
+ end
153
+
154
+ def set_audience_average_rating
155
+ end
156
+
157
+ def set_audience_number_of_ratings
158
+ end
159
+
160
+ def set_genres
161
+ @genres = []
162
+ @info_page.css('.movie_info p:first-of-type .content a').each do |genre|
163
+ @genres.push genre.text
164
+ end
165
+ end
166
+
167
+ def set_release
168
+ @release = info_page.css('.movie_info .left_col p:nth-of-type(3) .content span').text
169
+ end
170
+
171
+ def set_distributor
172
+ @distributor = @info_page.css('.movie_info .right_col p:nth-of-type(1)').text.gsub('Distributor:', '')
173
+ end
174
+
175
+ public
176
+
177
+ def director
178
+ @directors.first
179
+ end
180
+
181
+ def writer
182
+ @writers.first
183
+ end
184
+
185
+ end
186
+
187
+ end
@@ -0,0 +1,52 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rotten-tomatoes}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["atom smith"]
12
+ s.date = %q{2011-01-07}
13
+ s.description = %q{Allows you to search and get information about movies from rottentomatoes.com. Organizes returned information into easy to access attributes.}
14
+ s.email = %q{re5etsmyth@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "lib/rotten-tomatoes.rb",
26
+ "rotten-tomatoes.gemspec",
27
+ "test/helper.rb",
28
+ "test/test_rotten-tomatoes.rb"
29
+ ]
30
+ s.homepage = %q{http://github.com/re5et/rotten-tomatoes}
31
+ s.require_paths = ["lib"]
32
+ s.rubygems_version = %q{1.3.7}
33
+ s.summary = %q{Fetch information regarding movies from rottentomatoes.com}
34
+ s.test_files = [
35
+ "test/helper.rb",
36
+ "test/test_rotten-tomatoes.rb"
37
+ ]
38
+
39
+ if s.respond_to? :specification_version then
40
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
45
+ else
46
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
47
+ end
48
+ else
49
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
50
+ end
51
+ end
52
+
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'rotten-tomatoes'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestRottenTomatoes < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rotten-tomatoes
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - atom smith
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-01-07 00:00:00 -08:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: thoughtbot-shoulda
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :development
32
+ version_requirements: *id001
33
+ description: Allows you to search and get information about movies from rottentomatoes.com. Organizes returned information into easy to access attributes.
34
+ email: re5etsmyth@gmail.com
35
+ executables: []
36
+
37
+ extensions: []
38
+
39
+ extra_rdoc_files:
40
+ - LICENSE
41
+ - README.rdoc
42
+ files:
43
+ - .document
44
+ - LICENSE
45
+ - README.rdoc
46
+ - Rakefile
47
+ - VERSION
48
+ - lib/rotten-tomatoes.rb
49
+ - rotten-tomatoes.gemspec
50
+ - test/helper.rb
51
+ - test/test_rotten-tomatoes.rb
52
+ has_rdoc: true
53
+ homepage: http://github.com/re5et/rotten-tomatoes
54
+ licenses: []
55
+
56
+ post_install_message:
57
+ rdoc_options: []
58
+
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ requirements: []
78
+
79
+ rubyforge_project:
80
+ rubygems_version: 1.3.7
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Fetch information regarding movies from rottentomatoes.com
84
+ test_files:
85
+ - test/helper.rb
86
+ - test/test_rotten-tomatoes.rb