rotten-tomatoes 0.1.4 → 0.2.0
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.
- data/VERSION +1 -1
- data/lib/rotten-tomatoes.rb +114 -7
- data/rotten-tomatoes.gemspec +2 -2
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/rotten-tomatoes.rb
CHANGED
@@ -13,12 +13,17 @@ require 'open-uri'
|
|
13
13
|
module Rotten_tomatoes
|
14
14
|
|
15
15
|
Base_url = 'http://www.rottentomatoes.com'
|
16
|
-
|
16
|
+
Movie_search_url = Base_url + '/search/movie.php?searchby=movies&page=1&search='
|
17
|
+
Person_search_url = Base_url + '/search/person.php?searchby=celebs&page=1&search='
|
17
18
|
|
18
19
|
# Create a new instance of Rotten_tomatoes::Movie with the
|
19
20
|
# rottentomatoes.com movie path as an argument
|
20
|
-
def self.
|
21
|
-
Movie.new
|
21
|
+
def self.get_movie_info movie_path
|
22
|
+
Movie.new movie_path
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.get_person_info person_path
|
26
|
+
Person.new person_path
|
22
27
|
end
|
23
28
|
|
24
29
|
# Search rottentomatoes.com for the movie you are looking for
|
@@ -26,7 +31,7 @@ module Rotten_tomatoes
|
|
26
31
|
# will contain the 'info_url' you need to us Rotten_tomatoes:get_info
|
27
32
|
def self.find_movie movie
|
28
33
|
movies = []
|
29
|
-
url = URI.parse(URI.encode(
|
34
|
+
url = URI.parse(URI.encode(Movie_search_url + movie.to_s))
|
30
35
|
results = Nokogiri::HTML(open(url))
|
31
36
|
results.css('#movie_search_main tr').each do |row|
|
32
37
|
movies.push({
|
@@ -34,16 +39,33 @@ module Rotten_tomatoes
|
|
34
39
|
:plot => row.css('td:nth-of-type(3) p:nth-of-type(2)').inner_text.gsub(/\APlot:/, '').strip,
|
35
40
|
:year => row.css('.date').inner_text,
|
36
41
|
:director => row.css('td:nth-of-type(3) p:nth-of-type(3) a:first-of-type').inner_text,
|
37
|
-
:
|
42
|
+
:movie_url => row.css('td:nth-of-type(3) p:first-of-type a').attr('href').value
|
38
43
|
})
|
39
44
|
end
|
40
45
|
return movies
|
41
46
|
end
|
42
47
|
|
48
|
+
def self.find_person person
|
49
|
+
people = []
|
50
|
+
url = URI.parse(URI.encode(Person_search_url + person.to_s))
|
51
|
+
results = Nokogiri::HTML(open(url))
|
52
|
+
results.css('#contrib_search_main tbody a').each do |row|
|
53
|
+
people.push({
|
54
|
+
:name => row.text,
|
55
|
+
:person_url => row.attribute('href').value
|
56
|
+
})
|
57
|
+
end
|
58
|
+
return people
|
59
|
+
end
|
60
|
+
|
43
61
|
# Uses Rotten_tomatoes::get_info to fetch info for the first
|
44
62
|
# search result found with Rotten_tomatoes::find_movie
|
45
|
-
def self.
|
46
|
-
|
63
|
+
def self.lucky_get_movie_info movie
|
64
|
+
get_movie_info find_movie(movie).first[:movie_url]
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.lucky_get_person_info person
|
68
|
+
get_person_info find_person(person).first[:person_url]
|
47
69
|
end
|
48
70
|
|
49
71
|
# Rotten_tomatoes::Movie is a class that organizes the scraped
|
@@ -73,6 +95,7 @@ module Rotten_tomatoes
|
|
73
95
|
set_release
|
74
96
|
set_distributor
|
75
97
|
end
|
98
|
+
@info_page = nil
|
76
99
|
return self
|
77
100
|
end
|
78
101
|
|
@@ -188,4 +211,88 @@ module Rotten_tomatoes
|
|
188
211
|
|
189
212
|
end
|
190
213
|
|
214
|
+
class Person
|
215
|
+
|
216
|
+
attr_reader :name, :main_role, :picture, :highest_rated, :lowest_rated, :birthdate, :birthplace, :age, :bio, :number_of_movies, :box_office, :movies
|
217
|
+
|
218
|
+
def initialize person_url
|
219
|
+
|
220
|
+
@info_page = Nokogiri::HTML(open(URI.parse(Rotten_tomatoes::Base_url + person_url + '?items=999')))
|
221
|
+
if @info_page
|
222
|
+
set_movies
|
223
|
+
set_name
|
224
|
+
set_main_role
|
225
|
+
set_picture
|
226
|
+
set_highest_rated
|
227
|
+
set_lowest_rated
|
228
|
+
set_birthdate
|
229
|
+
set_birthplace
|
230
|
+
set_age
|
231
|
+
set_bio
|
232
|
+
set_number_of_movies
|
233
|
+
set_box_office
|
234
|
+
end
|
235
|
+
@info_page = nil
|
236
|
+
return self
|
237
|
+
end
|
238
|
+
|
239
|
+
def set_name
|
240
|
+
@name = @info_page.css('h1.celeb_title').text
|
241
|
+
end
|
242
|
+
|
243
|
+
def set_main_role
|
244
|
+
@main_role = @info_page.css('#breadcrumb .subLevelCrumb').text.gsub('/', '').chomp('s')
|
245
|
+
end
|
246
|
+
|
247
|
+
def set_picture
|
248
|
+
@picture = @info_page.css('#mainImage').attribute('src').value
|
249
|
+
end
|
250
|
+
|
251
|
+
def set_highest_rated
|
252
|
+
highest_rated_url = @info_page.css('#celebRatings p:first a').attribute('href').value
|
253
|
+
@highest_rated = @movies[@movies.index {|movie| movie[:movie_url] == highest_rated_url}]
|
254
|
+
end
|
255
|
+
|
256
|
+
def set_lowest_rated
|
257
|
+
lowest_rated_url = @info_page.css('#celebRatings p:nth-of-type(2) a').attribute('href').value
|
258
|
+
@lowest_rated = @movies[@movies.index {|movies| movies[:movie_url] == lowest_rated_url}]
|
259
|
+
end
|
260
|
+
|
261
|
+
def set_birthdate
|
262
|
+
@birthdate = Time.parse @info_page.css('#celeb_bio p:first').text.split("Birthdate: ").last.strip
|
263
|
+
end
|
264
|
+
|
265
|
+
def set_birthplace
|
266
|
+
@birthplace = @info_page.css('#celeb_bio p:nth-of-type(2)').text.split("Birthplace: ").last.strip
|
267
|
+
end
|
268
|
+
|
269
|
+
def set_age
|
270
|
+
@age = ((Time.now - @birthdate) / 60 / 60 / 24 / 365).floor
|
271
|
+
end
|
272
|
+
|
273
|
+
def set_bio
|
274
|
+
@bio = @info_page.css('#celeb_bio p:nth-of-type(3)').text.split("Bio:").last.gsub('[More...]', '').strip
|
275
|
+
end
|
276
|
+
|
277
|
+
def set_number_of_movies
|
278
|
+
@number_of_movies = @movies.size
|
279
|
+
end
|
280
|
+
|
281
|
+
def set_box_office
|
282
|
+
@box_office = @info_page.css('#celeb_stats div.celeb_stat.last').text.split(":").last.strip
|
283
|
+
end
|
284
|
+
|
285
|
+
def set_movies
|
286
|
+
@movies = []
|
287
|
+
@info_page.css('#filmographyTbl tbody tr').each do |movie|
|
288
|
+
@movies.push({
|
289
|
+
:title => movie.css('.filmographyTbl_titleCol').text.strip,
|
290
|
+
:movie_url => movie.css('.filmographyTbl_titleCol a').attribute('href').value,
|
291
|
+
:credit => movie.css('.filmographyTbl_creditCol').text.strip
|
292
|
+
})
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
end
|
297
|
+
|
191
298
|
end
|
data/rotten-tomatoes.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rotten-tomatoes}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["atom smith"]
|
12
|
-
s.date = %q{2011-01-
|
12
|
+
s.date = %q{2011-01-19}
|
13
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
14
|
s.email = %q{re5etsmyth@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- atom smith
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-01-
|
17
|
+
date: 2011-01-19 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|