filmaffinity 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 85e6ac65baf2563e2cee42cff1ac1d2a74c8b679
4
- data.tar.gz: a2ab5f9140d11a6d955e3b6b3c61c123cd6978cd
3
+ metadata.gz: 59143d52d028335079f76b6cb8c075310c7b53fe
4
+ data.tar.gz: 48d2789e4b105327f6d5075a3d52cfe2952cfa44
5
5
  SHA512:
6
- metadata.gz: 7b4d7be82f19761f68dd9bb87412e8124376f6604014669332bb6ff152212c2db3f22f72bd00c79559b5893478d9209063d6b2050f26dffe62f635e052c47998
7
- data.tar.gz: 3d0461b12921eaa288fe47e0fa4da924158ea6a7abe0a2a8e55432747fe1e9d552192970e2210ab2d90e5069ba07f7fc9e328f70966dbb3801bf280c2bf96003
6
+ metadata.gz: 72e2a3cd9099bac624451f145cc5986635cb9498a0bcf9ef0ca201021c0ae1b549b65c2642a398f7dc82415017284c39d63fbcd77ab923fc710daead1c7c65dc
7
+ data.tar.gz: 914916c362fe6188a508abc63fb2fea7f8b291f723cce40cd55a9c90924852f5ac20bf1a3b402489c29a837713d70931cb994730d579064f715a656f6b0d2b30
data/.gitignore ADDED
@@ -0,0 +1,43 @@
1
+ ## Ignore Mac DS_Store files
2
+ .DS_Store
3
+ ## Ignore test folder
4
+ /.test/
5
+
6
+ *.gem
7
+ *.rbc
8
+ /.config
9
+ /coverage/
10
+ /InstalledFiles
11
+ /pkg/
12
+ /spec/reports/
13
+ /test/tmp/
14
+ /test/version_tmp/
15
+ /tmp/
16
+
17
+ ## Specific to RubyMotion:
18
+ .dat*
19
+ .repl_history
20
+ build/
21
+
22
+ ## Documentation cache and generated files:
23
+ /.yardoc/
24
+ /_yardoc/
25
+ /doc/
26
+ /rdoc/
27
+
28
+ ## Environment normalisation:
29
+ /.bundle/
30
+ /vendor/bundle
31
+ /lib/bundler/man/
32
+
33
+ # for a library or gem, you might want to ignore these files since the code is
34
+ # intended to run in multiple environments; otherwise, check them in:
35
+ # Gemfile.lock
36
+ # .ruby-version
37
+ # .ruby-gemset
38
+
39
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
40
+ .rvmrc
41
+
42
+ # playground file
43
+ /playground.rb
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org/"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,32 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.2.5)
5
+ fakeweb (1.3.0)
6
+ mini_portile2 (2.0.0)
7
+ nokogiri (1.6.7.2)
8
+ mini_portile2 (~> 2.0.0.rc2)
9
+ rspec (3.4.0)
10
+ rspec-core (~> 3.4.0)
11
+ rspec-expectations (~> 3.4.0)
12
+ rspec-mocks (~> 3.4.0)
13
+ rspec-core (3.4.4)
14
+ rspec-support (~> 3.4.0)
15
+ rspec-expectations (3.4.0)
16
+ diff-lcs (>= 1.2.0, < 2.0)
17
+ rspec-support (~> 3.4.0)
18
+ rspec-mocks (3.4.1)
19
+ diff-lcs (>= 1.2.0, < 2.0)
20
+ rspec-support (~> 3.4.0)
21
+ rspec-support (3.4.1)
22
+
23
+ PLATFORMS
24
+ ruby
25
+
26
+ DEPENDENCIES
27
+ fakeweb
28
+ nokogiri
29
+ rspec
30
+
31
+ BUNDLED WITH
32
+ 1.11.2
data/README.md ADDED
@@ -0,0 +1 @@
1
+ #FilmAffinity Scraper Gem
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new do |task|
4
+ task.rspec_opts = ['--color', '--format', 'doc']
5
+ end
@@ -0,0 +1,18 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'filmaffinity'
3
+ s.version = '0.0.2'
4
+ s.date = '2016-04-05'
5
+ s.summary = "filmaffinity"
6
+ s.description = "Easily use Ruby or the command line to find information on Filmaffinity.com"
7
+ s.authors = ["David Santos, Oriol Bellido"]
8
+ s.email = 'dsantosmerino92@gmail.com'
9
+ s.files = `git ls-files`.split("\n")
10
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
11
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
12
+ s.require_paths = ['lib']
13
+ s.homepage = 'http://rubygems.org/gems/filmaffinity'
14
+ s.license = 'MIT'
15
+ s.add_dependency 'nokogiri', ' ~> 1.6'
16
+ s.add_development_dependency 'rake', '~> 10.0'
17
+ s.add_development_dependency 'rspec', '~> 3.3'
18
+ end
@@ -0,0 +1,84 @@
1
+ module FilmAffinity
2
+ class Movie
3
+ attr_reader :id, :title
4
+ def initialize id,title
5
+ @id = id
6
+ @title = title
7
+ end
8
+
9
+ def document_html
10
+ @document_html ||= Nokogiri::HTML(self.generate_html)
11
+ end
12
+
13
+ def generate_html
14
+ open("http://www.filmaffinity.com/es/film#{@id}.html")
15
+ end
16
+
17
+ def year
18
+ document_html.at('dd[itemprop="datePublished"]').content[/\d+/].to_i
19
+ end
20
+
21
+ def duration
22
+ document_html.at('dd[itemprop="duration"]').content[/\d+/].to_i
23
+ end
24
+
25
+ def country
26
+ raw_country = document_html.at("#country-img").next_sibling.content
27
+ raw_country.gsub(/\A[[:space:]]+|[[:space:]]+\z/, '')
28
+ end
29
+
30
+ def director
31
+ raw_director = document_html.at('a[itemprop="url"]').content
32
+ raw_director.strip
33
+ end
34
+
35
+ def script
36
+ document_html.at('dt:contains("Guión")').next_sibling.next_sibling.content
37
+ end
38
+
39
+ def music
40
+ document_html.at('dt:contains("Música")').next_sibling.next_sibling.content
41
+ end
42
+
43
+ def photography
44
+ document_html.at('dt:contains("Fotografía")').next_sibling.next_sibling.content
45
+ end
46
+
47
+ def cast
48
+ actors = []
49
+ node = document_html.search('span[itemprop="actor"]')
50
+ node.each do |actor|
51
+ actors << actor.at('span[itemprop="name"]').content.strip
52
+ end
53
+ actors
54
+ end
55
+
56
+ def company
57
+ document_html.at('dt:contains("Productora")').next_sibling.next_sibling.content
58
+ end
59
+
60
+ def genres
61
+ genres = []
62
+ node = document_html.at('dt:contains("Género")').next_sibling.next_sibling
63
+ raw_genres = node.search("a")
64
+ raw_genres.each do |raw_genre|
65
+ genres << raw_genre.content.strip
66
+ end
67
+ genres
68
+
69
+ end
70
+
71
+ def sinopsis
72
+ document_html.at('dd[itemprop="description"]').content
73
+ end
74
+
75
+ def prizes
76
+
77
+ end
78
+
79
+ def rating
80
+ raw_rating = document_html.at('div[itemprop="ratingValue"]').content.strip
81
+ raw_rating.gsub(",",".").to_f
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,43 @@
1
+ require "cgi"
2
+
3
+ module FilmAffinity
4
+ class Search
5
+ def initialize query
6
+ @query = query
7
+ end
8
+
9
+ def movies
10
+ @movies ||= (exact_match? ? parse_movie : parse_movies)
11
+ end
12
+
13
+ def exact_match?
14
+ !document_html.at(".z-movie").nil?
15
+ end
16
+
17
+ def document_html
18
+ @document_html ||= Nokogiri::HTML(self.generate_html)
19
+ end
20
+
21
+ def generate_html
22
+ open("http://www.filmaffinity.com/es/search.php?stext=#{CGI.escape(@query)}&stype=title")
23
+ end
24
+
25
+ def parse_movie
26
+ id = document_html.at('meta[property="og:url"]')['content'][/\d+/].to_i
27
+ title = document_html.at('meta[property="og:title"]')['content']
28
+ [FilmAffinity::Movie.new(id,title)]
29
+ end
30
+
31
+ def parse_movies
32
+ movies = []
33
+ document_html.search(".movie-card.movie-card-1").each do |movie_card|
34
+ id = movie_card["data-movie-id"].to_i
35
+ title = movie_card.search(".mc-title a").first.content.strip
36
+ movie = FilmAffinity::Movie.new id, title
37
+ movies << movie
38
+ end
39
+ movies
40
+ end
41
+
42
+ end
43
+ end
File without changes
@@ -0,0 +1,7 @@
1
+ require "rspec/expectations"
2
+
3
+ RSpec::Matchers.define :include_movie do |expected|
4
+ match do |movies|
5
+ movies.any? { |movie| movie.title == expected.title }
6
+ end
7
+ end
@@ -0,0 +1,103 @@
1
+ require_relative "../spec_helper"
2
+
3
+ describe "FilmAffinity::Movie" do
4
+
5
+ describe "#rating" do
6
+ subject(:movie) { FilmAffinity::Movie.new(504889, "El show de Truman (Una vida en directo)") }
7
+ it "should return an Float" do
8
+ expect(movie.rating).to be_a(Float)
9
+ end
10
+ end
11
+
12
+ describe "#year" do
13
+ subject(:movie) { FilmAffinity::Movie.new(504889, "El show de Truman (Una vida en directo)") }
14
+ it "should return an Fixnum" do
15
+ expect(movie.year).to be_an(Fixnum)
16
+ end
17
+ it "should return 1998" do
18
+ expect(movie.year).to eq(1998)
19
+ end
20
+ end
21
+
22
+ describe "#duration" do
23
+ subject(:movie) { FilmAffinity::Movie.new(504889, "El show de Truman (Una vida en directo)") }
24
+ it "should return an Fixnum" do
25
+ expect(movie.duration).to be_a(Fixnum)
26
+ end
27
+ it "should return 103" do
28
+ expect(movie.duration).to eq(103)
29
+ end
30
+ end
31
+
32
+ describe "#country" do
33
+ subject(:movie) { FilmAffinity::Movie.new(504889, "El show de Truman (Una vida en directo)") }
34
+ it "should return a String" do
35
+ expect(movie.country).to be_a(String)
36
+ end
37
+ it "should return 'Estados Unidos'" do
38
+ expect(movie.country).to eq("Estados Unidos")
39
+ end
40
+ end
41
+
42
+ describe "#director" do
43
+ subject(:movie) { FilmAffinity::Movie.new(504889, "El show de Truman (Una vida en directo)") }
44
+ it "should return a String" do
45
+ expect(movie.director).to be_a(String)
46
+ end
47
+ it "should return 'Peter Weir'" do
48
+ expect(movie.director).to eq("Peter Weir")
49
+ end
50
+ end
51
+
52
+ describe "#script" do
53
+ subject(:movie) { FilmAffinity::Movie.new(504889, "El show de Truman (Una vida en directo)") }
54
+ it "should return a String" do
55
+ expect(movie.script).to be_a(String)
56
+ end
57
+ it "should return 'Andrew Niccol'" do
58
+ expect(movie.script).to eq("Andrew Niccol")
59
+ end
60
+ end
61
+
62
+ describe "#cast" do
63
+ subject(:movie) { FilmAffinity::Movie.new(504889, "El show de Truman (Una vida en directo)") }
64
+ it "should return an Array" do
65
+ expect(movie.cast).to be_an(Array)
66
+ end
67
+ it "should to include the passed cast" do
68
+ expected_cast = [
69
+ "Jim Carrey",
70
+ "Laura Linney",
71
+ "Noah Emmerich",
72
+ "Ed Harris"
73
+ ]
74
+ expect(movie.cast).to include(*expected_cast)
75
+ end
76
+ end
77
+
78
+ describe "#company" do
79
+ subject(:movie) { FilmAffinity::Movie.new(504889, "El show de Truman (Una vida en directo)") }
80
+ it "should return a String" do
81
+ expect(movie.company).to be_a(String)
82
+ end
83
+ it "should return 'Paramount Pictures / Scott Rudin Productions'" do
84
+ expect(movie.company).to eq("Paramount Pictures / Scott Rudin Productions")
85
+ end
86
+ end
87
+
88
+ describe "#genres" do
89
+ subject(:movie) { FilmAffinity::Movie.new(504889, "El show de Truman (Una vida en directo)") }
90
+ it "should return an Array" do
91
+ expect(movie.genres).to be_an(Array)
92
+ end
93
+ it "should to include the passed genres" do
94
+ expected_genres = [
95
+ "Drama",
96
+ "Comedia",
97
+ "Sátira"
98
+ ]
99
+ expect(movie.genres).to include(*expected_genres)
100
+ end
101
+ end
102
+
103
+ end
@@ -0,0 +1,50 @@
1
+ require_relative "../spec_helper"
2
+ require_relative "matchers/include-movie"
3
+
4
+
5
+ describe "FilmAffinity::Search" do
6
+
7
+ describe "#create_document_html" do
8
+ subject(:search) { FilmAffinity::Search.new("truman") }
9
+
10
+ it "#create_document_html" do
11
+ document_html = search.document_html
12
+ expect(document_html).to be_an(Nokogiri::HTML::Document)
13
+ end
14
+
15
+ end
16
+
17
+ describe "#movies" do
18
+ subject(:search) { FilmAffinity::Search.new("truman") }
19
+
20
+ it "should return an array" do
21
+ movies = search.movies
22
+ expect(movies).to be_an(Array)
23
+ end
24
+ it "should return just FilmAffinity::Movie objects only" do
25
+ movies = search.movies
26
+ movies.each { |movie| expect(movie).to be_an(FilmAffinity::Movie) }
27
+ end
28
+ it "should include 'Truman Show'" do
29
+ movies = search.movies
30
+ truman_movie = FilmAffinity::Movie.new 504889, "El show de Truman (Una vida en directo)"
31
+ expect(movies).to include_movie(truman_movie)
32
+ end
33
+ end
34
+
35
+ describe "#parse_movie" do
36
+ #Get a direct result from a specific searchs
37
+ subject(:search) { FilmAffinity::Search.new("truman show") }
38
+
39
+ it "should parse id" do
40
+ id = 504889
41
+ expect(id).to eq(search.movies.first.id)
42
+ end
43
+
44
+ it "should parse title" do
45
+ title = "El show de Truman (Una vida en directo) (1998)"
46
+ expect(title).to eq(search.movies.first.title)
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,3 @@
1
+ require 'rspec'
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + "/../lib")
3
+ require 'filmaffinity'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filmaffinity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Santos, Oriol Bellido
@@ -9,14 +9,69 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2016-04-05 00:00:00.000000000 Z
12
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.3'
13
55
  description: Easily use Ruby or the command line to find information on Filmaffinity.com
14
56
  email: dsantosmerino92@gmail.com
15
57
  executables: []
16
58
  extensions: []
17
59
  extra_rdoc_files: []
18
60
  files:
61
+ - ".gitignore"
62
+ - Gemfile
63
+ - Gemfile.lock
64
+ - README.md
65
+ - Rakefile
66
+ - filmaffinity.gemspec
19
67
  - lib/filmaffinity.rb
68
+ - lib/filmaffinity/movie.rb
69
+ - lib/filmaffinity/search.rb
70
+ - lib/filmaffinity/top.rb
71
+ - spec/filmaffinity/matchers/include-movie.rb
72
+ - spec/filmaffinity/movie_spec.rb
73
+ - spec/filmaffinity/search_spec.rb
74
+ - spec/spec_helper.rb
20
75
  homepage: http://rubygems.org/gems/filmaffinity
21
76
  licenses:
22
77
  - MIT
@@ -41,5 +96,9 @@ rubygems_version: 2.4.6
41
96
  signing_key:
42
97
  specification_version: 4
43
98
  summary: filmaffinity
44
- test_files: []
99
+ test_files:
100
+ - spec/filmaffinity/matchers/include-movie.rb
101
+ - spec/filmaffinity/movie_spec.rb
102
+ - spec/filmaffinity/search_spec.rb
103
+ - spec/spec_helper.rb
45
104
  has_rdoc: