bootleg 0.0.1

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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'nokogiri'
4
+ gem 'mechanize'
5
+
6
+ # Specify your gem's dependencies in bootleg.gemspec
7
+
8
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Marius Lucian Pop
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Bootleg
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'bootleg'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install bootleg
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,3 @@
1
+ == Bootleg - moviefone scraper
2
+
3
+ This is a gem in development. It's purpose is to scrape theaters, movies, showtimes and other details from moviefone.com .
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bootleg/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "bootleg"
8
+ gem.version = Bootleg::VERSION
9
+ gem.authors = ["Marius L. Pop"]
10
+ gem.email = ["marius@mlpinit.com"]
11
+ gem.description = %q{ Scraping theaters, movies, showtimes and other relevant data from movifone.com}
12
+ gem.summary = %q{ ...comming soon...}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "nokogiri"
21
+ gem.add_dependency "mechanize"
22
+ gem.add_development_dependency "rspec"
23
+ end
@@ -0,0 +1,5 @@
1
+ require "bootleg/version"
2
+
3
+ module Bootleg
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,3 @@
1
+ module Bootleg
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,30 @@
1
+ require 'mechanize'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+ require_relative 'finder'
5
+ require_relative 'modules/theater'
6
+
7
+ class Extractor
8
+
9
+ attr_reader :page_theaters
10
+
11
+ def initialize(page)
12
+ @page = (Nokogiri::HTML(open(page)))
13
+ @page_theaters = []
14
+ extract_movies
15
+ end
16
+
17
+ def extract_movies
18
+ theaters.each do |theater|
19
+ theater.extend Theater
20
+ theater_info = { name: theater.name, href: theater.link, movies: theater.movies}
21
+ @page_theaters << theater_info
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def theaters
28
+ @page.css('div.theater')
29
+ end
30
+ end
@@ -0,0 +1,14 @@
1
+ require_relative 'modules/zipcode'
2
+ require_relative 'modules/href'
3
+
4
+ class Finder
5
+ def initialize(zipcode = '20906')
6
+ zipcode.extend Zipcode
7
+ @href = zipcode.search
8
+ end
9
+
10
+ def hrefs
11
+ @href.extend Href
12
+ @href.all
13
+ end
14
+ end
@@ -0,0 +1,21 @@
1
+ require_relative 'finder'
2
+ require_relative 'extractor'
3
+
4
+ class Manager
5
+ def initialize(zipcode)
6
+ @zipcode = zipcode
7
+ @pages ||= find_pages
8
+ @all_theaters = []
9
+ end
10
+
11
+ def find_pages
12
+ Finder.new(@zipcode).hrefs
13
+ end
14
+
15
+ def extract_theaters
16
+ @pages.each do |page|
17
+ @all_theaters << Extractor.new(page).page_theaters
18
+ end
19
+ @all_theaters.flatten
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ module Href
2
+ def all
3
+ pages = []
4
+ count.times { |nr| pages << url + nr.to_s }
5
+ pages
6
+ end
7
+
8
+ private
9
+
10
+ def count
11
+ self.links.select { |link| link.text.size < 3 and link.text =~ /\d/ }.last.text.to_i
12
+ end
13
+
14
+ def url
15
+ self.uri.to_s + '?page='
16
+ end
17
+ end
18
+
@@ -0,0 +1,22 @@
1
+ module Movie
2
+ def details
3
+ self.css('div.movietitle')
4
+ end
5
+
6
+ def name
7
+ details.css('a').text.strip
8
+ end
9
+
10
+ def link
11
+ "http://www.moviefone.com" + details.css('a').attribute('href').value
12
+ end
13
+
14
+ def showtimes
15
+ values = []
16
+ showtimes = self.css('a.gt').empty? ? self.css('span.stDisplay') : self.css('a.gt')
17
+ showtimes.each do |time|
18
+ values << time.text
19
+ end
20
+ values
21
+ end
22
+ end
@@ -0,0 +1,26 @@
1
+ require_relative 'movie'
2
+
3
+ module Theater
4
+ def details
5
+ self.css('h3.title').css('a')
6
+ end
7
+
8
+ def name
9
+ details.text.strip
10
+ end
11
+
12
+ def link
13
+ details.attribute('href').value
14
+ end
15
+
16
+ def movies
17
+ movies = self.css('div.movie-listing.first')
18
+ values = []
19
+ movies.each do |movie|
20
+ movie.extend Movie
21
+ movie_info = { name: movie.name, href: movie.link, showtimes: movie.showtimes }
22
+ values << movie_info
23
+ end
24
+ values
25
+ end
26
+ end
@@ -0,0 +1,12 @@
1
+ require 'mechanize'
2
+
3
+ module Zipcode
4
+ def search
5
+ agent = Mechanize.new
6
+ page = agent.get("http://www.moviefone.com")
7
+ search_form = page.form_with id: 'frm-search'
8
+ search_form.fields[1].value = self
9
+ agent.submit search_form
10
+ end
11
+ end
12
+
@@ -0,0 +1,8 @@
1
+ require_relative 'manager'
2
+ class Presenter
3
+ attr_reader :theaters
4
+
5
+ def initialize(zipcode)
6
+ @theaters ||= Manager.new(zipcode).extract_theaters
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bootleg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Marius L. Pop
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: mechanize
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: ! ' Scraping theaters, movies, showtimes and other relevant data from
63
+ movifone.com'
64
+ email:
65
+ - marius@mlpinit.com
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - Gemfile
72
+ - LICENSE.txt
73
+ - README.md
74
+ - README.rdoc
75
+ - Rakefile
76
+ - bootleg.gemspec
77
+ - lib/bootleg.rb
78
+ - lib/bootleg/version.rb
79
+ - lib/extractor.rb
80
+ - lib/finder.rb
81
+ - lib/manager.rb
82
+ - lib/modules/href.rb
83
+ - lib/modules/movie.rb
84
+ - lib/modules/theater.rb
85
+ - lib/modules/zipcode.rb
86
+ - lib/presenter.rb
87
+ homepage: ''
88
+ licenses: []
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 1.8.24
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: ! '...comming soon...'
111
+ test_files: []