odeon_uk 1.0.0 → 1.1.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.
- checksums.yaml +15 -0
- data/.rdoc_options +16 -0
- data/.travis.yml +4 -0
- data/README.md +2 -1
- data/lib/odeon_uk/cinema.rb +75 -6
- data/lib/odeon_uk/film.rb +35 -1
- data/lib/odeon_uk/internal/film_with_screenings_parser.rb +6 -3
- data/lib/odeon_uk/screening.rb +6 -4
- data/lib/odeon_uk/version.rb +1 -1
- data/lib/odeon_uk.rb +4 -2
- data/odeon_uk.gemspec +1 -1
- data/test/fixtures/odeon-bfi-imax.html +3061 -0
- data/test/fixtures/odeon-london-leicester-square.html +2847 -0
- data/test/lib/odeon_uk/cinema_test.rb +169 -14
- data/test/lib/odeon_uk/film_test.rb +82 -0
- data/test/lib/odeon_uk/internal/film_with_screenings_parser_test.rb +10 -6
- data/test/lib/odeon_uk/screening_test.rb +15 -3
- metadata +13 -20
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MmYxYzliYzA4OTE4ODMzNWRkYjU2ZGM1ZGJhOGYzOGNhZWMwMGM5Mw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ODMwZWU5MThmYmI4ZTA0MzI3ZGUzMmNkNDVjZWY0YTAyOWVhM2YyZQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ODY3NmEyM2U3OTY3ZjM1OWFlYmYwYWYzYjEzMjg4MWI4NjFiNDRhNjMzYTY3
|
10
|
+
ODBhYmI5NDY0ODRhNzk2MjE2NzkwOGE3YTE4MjA4M2Y3YzBjMTJmMTczNDAy
|
11
|
+
MmVmNmEyNDEwNDNkNTRmNmVkZWQwYWQyY2IyYzYxNWFmZDIxM2U=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YjhmNmMxYjRlZTBiZmEyY2FiNzdlYjEwMDllYmUzZmFmOWQwNGMzMDIwMzVm
|
14
|
+
ZGY5MzJlNzkzNDUyYzc5NGM0NDJiMzQ1NzRiYzFiNWYwN2UyZTMzZTI0ZTRk
|
15
|
+
ZGNjM2RhOGFjNGQ0MzdmZTM1MDBmZmNlZGNhMWM4Yjk4YmQ2Mzc=
|
data/.rdoc_options
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
--- !ruby/object:RDoc::Options
|
2
|
+
encoding: UTF-8
|
3
|
+
static_path: []
|
4
|
+
rdoc_include:
|
5
|
+
- .
|
6
|
+
charset: UTF-8
|
7
|
+
exclude:
|
8
|
+
hyperlink_all: false
|
9
|
+
line_numbers: false
|
10
|
+
main_page:
|
11
|
+
markup: tomdoc
|
12
|
+
show_hash: false
|
13
|
+
tab_width: 8
|
14
|
+
title:
|
15
|
+
visibility: :protected
|
16
|
+
webcvs:
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# OdeonUk
|
2
2
|
|
3
|
-
A simple gem to parse the
|
3
|
+
A simple gem to parse the [Odeon UK website](http://odeon.co.uk) and spit out useful formatted info.
|
4
4
|
|
5
5
|
[](https://codeclimate.com/github/andycroll/odeon_uk)
|
6
|
+
[](https://travis-ci.org/andycroll/odeon_uk)
|
6
7
|
|
7
8
|
## Installation
|
8
9
|
|
data/lib/odeon_uk/cinema.rb
CHANGED
@@ -22,8 +22,8 @@ module OdeonUk
|
|
22
22
|
def initialize(id, name, url)
|
23
23
|
@brand = 'Odeon'
|
24
24
|
@id = id.to_i
|
25
|
-
@name = name
|
26
|
-
@slug = name.downcase.gsub(/[^0-9a-z ]/,'').gsub(/\s+/, '-')
|
25
|
+
@name = name.gsub('London - ','')
|
26
|
+
@slug = @name.downcase.gsub(/[^0-9a-z ]/,'').gsub(/\s+/, '-')
|
27
27
|
@url = (url[0] == '/') ? "http://www.odeon.co.uk#{url}" : url
|
28
28
|
end
|
29
29
|
|
@@ -59,6 +59,27 @@ module OdeonUk
|
|
59
59
|
all.select { |cinema| cinema.id == id }[0]
|
60
60
|
end
|
61
61
|
|
62
|
+
# Public: Returns adress hash of an Odeon cinema
|
63
|
+
#
|
64
|
+
# Examples
|
65
|
+
#
|
66
|
+
# cinema = OdeonUk::Cinema.find('71')
|
67
|
+
# cinema.adr
|
68
|
+
# # => { street_address: 'Kingswest',
|
69
|
+
# locality: 'Brighton',
|
70
|
+
# postal_code: 'BN1 2RE',
|
71
|
+
# country_name: 'United Kingdom' }
|
72
|
+
#
|
73
|
+
# Returns an array of strings or nil
|
74
|
+
def adr
|
75
|
+
{
|
76
|
+
street_address: street_address,
|
77
|
+
locality: locality,
|
78
|
+
postal_code: postal_code,
|
79
|
+
country: 'United Kingdom'
|
80
|
+
}
|
81
|
+
end
|
82
|
+
|
62
83
|
# Public: Returns films for an Odeon cinema
|
63
84
|
#
|
64
85
|
# Examples
|
@@ -72,7 +93,34 @@ module OdeonUk
|
|
72
93
|
film_nodes.map do |node|
|
73
94
|
parser = OdeonUk::Internal::FilmWithScreeningsParser.new node.to_s
|
74
95
|
OdeonUk::Film.new parser.film_name
|
75
|
-
end
|
96
|
+
end.uniq
|
97
|
+
end
|
98
|
+
|
99
|
+
# Public: Returns the locality (town) of an Odeon cinema
|
100
|
+
#
|
101
|
+
# Examples
|
102
|
+
#
|
103
|
+
# cinema = OdeonUk::Cinema.find('71')
|
104
|
+
# cinema.locality
|
105
|
+
# # => 'Brighton'
|
106
|
+
#
|
107
|
+
# Returns a String
|
108
|
+
def locality
|
109
|
+
address_node.text.match(/\w+(\s\w+){0,}\s+(\w+(\s\w+){0,})/)[2]
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
# Public: Returns the postal code of an Odeon cinema
|
114
|
+
#
|
115
|
+
# Examples
|
116
|
+
#
|
117
|
+
# cinema = OdeonUk::Cinema.find('71')
|
118
|
+
# cinema.postal_code
|
119
|
+
# # => 'BN1 2RE'
|
120
|
+
#
|
121
|
+
# Returns a String
|
122
|
+
def postal_code
|
123
|
+
address_node.text.match(/[A-Z]{1,2}\d{1,2}[A-Z]?\s\d{1,2}[A-Z]{1,2}/)[0]
|
76
124
|
end
|
77
125
|
|
78
126
|
# Public: Returns screenings for an Odeon cinema
|
@@ -87,9 +135,9 @@ module OdeonUk
|
|
87
135
|
def screenings
|
88
136
|
film_nodes.map do |node|
|
89
137
|
parser = OdeonUk::Internal::FilmWithScreeningsParser.new node.to_s
|
90
|
-
parser.showings.map do |screening_type,
|
91
|
-
|
92
|
-
OdeonUk::Screening.new parser.film_name, self.name,
|
138
|
+
parser.showings.map do |screening_type, times_urls|
|
139
|
+
times_urls.map do |array|
|
140
|
+
OdeonUk::Screening.new parser.film_name, self.name, array[0], array[1], screening_type
|
93
141
|
end
|
94
142
|
end
|
95
143
|
end.flatten
|
@@ -111,6 +159,19 @@ module OdeonUk
|
|
111
159
|
screenings.select { |s| s.film_name == film_name }
|
112
160
|
end
|
113
161
|
|
162
|
+
# Public: Returns the street adress of an Odeon cinema
|
163
|
+
#
|
164
|
+
# Examples
|
165
|
+
#
|
166
|
+
# cinema = OdeonUk::Cinema.find('71')
|
167
|
+
# cinema.street_address
|
168
|
+
# # => 'Kingswest'
|
169
|
+
#
|
170
|
+
# Returns a String
|
171
|
+
def street_address
|
172
|
+
address_node.text.match(/\A\s+(\w+(\s\w+){0,})/)[1]
|
173
|
+
end
|
174
|
+
|
114
175
|
private
|
115
176
|
|
116
177
|
def self.cinema_links
|
@@ -133,10 +194,18 @@ module OdeonUk
|
|
133
194
|
@sitemap_response ||= HTTParty.get('http://www.odeon.co.uk/sitemap/')
|
134
195
|
end
|
135
196
|
|
197
|
+
def address_node
|
198
|
+
parsed_cinema.css('.gethere .span4 .description')[0]
|
199
|
+
end
|
200
|
+
|
136
201
|
def cinema_response
|
137
202
|
@cinema_response ||= HTTParty.get(@url)
|
138
203
|
end
|
139
204
|
|
205
|
+
def parsed_cinema
|
206
|
+
Nokogiri::HTML(cinema_response)
|
207
|
+
end
|
208
|
+
|
140
209
|
def film_nodes
|
141
210
|
parsed_showtimes.css('.film-detail')
|
142
211
|
end
|
data/lib/odeon_uk/film.rb
CHANGED
@@ -2,17 +2,51 @@ module OdeonUk
|
|
2
2
|
|
3
3
|
# Public: The object representing a film on the Odeon UK website
|
4
4
|
class Film
|
5
|
+
include Comparable
|
5
6
|
|
6
7
|
# Public: Returns the String name of the film
|
7
8
|
attr_reader :name
|
9
|
+
# Public: Returns the String slug of the film
|
10
|
+
attr_reader :slug
|
8
11
|
|
9
12
|
# Public: Initialize a screening
|
10
13
|
#
|
11
14
|
# name - String of the film name
|
12
15
|
def initialize(name)
|
13
16
|
@name = name
|
17
|
+
@slug = name.downcase.gsub(/[^0-9a-z ]/,'').gsub(/\s+/, '-')
|
14
18
|
end
|
15
19
|
|
16
|
-
|
20
|
+
# Public: Allows sort on objects
|
21
|
+
def <=> other
|
22
|
+
self.slug <=> other.slug
|
23
|
+
end
|
17
24
|
|
25
|
+
# Public: Check an object is the same as another object.
|
26
|
+
#
|
27
|
+
# True if both objects are the same exact object, or if they are of the same
|
28
|
+
# type and share an equal slug
|
29
|
+
#
|
30
|
+
# Guided by http://woss.name/2011/01/20/equality-comparison-and-ordering-in-ruby/
|
31
|
+
#
|
32
|
+
# object - object to be compared
|
33
|
+
#
|
34
|
+
# Returns Boolean
|
35
|
+
def eql? other
|
36
|
+
self.class == other.class && self == other
|
37
|
+
end
|
38
|
+
|
39
|
+
# Public: generates hash of slug in order to allow two records of the same
|
40
|
+
# type and id to work with something like:
|
41
|
+
#
|
42
|
+
# [ Film.new('ABC'), Film.new('DEF') ] & [ Film.new('DEF'), Film.new('GHI') ]
|
43
|
+
# #=> [ Film.new('DEF') ]
|
44
|
+
#
|
45
|
+
# Guided by http://woss.name/2011/01/20/equality-comparison-and-ordering-in-ruby/
|
46
|
+
#
|
47
|
+
# Returns an Integer hash of the slug
|
48
|
+
def hash
|
49
|
+
self.slug.hash
|
50
|
+
end
|
51
|
+
end
|
18
52
|
end
|
@@ -39,11 +39,14 @@ module OdeonUk
|
|
39
39
|
@nokogiri_html.css('.times-all.accordion-group').inject({}) do |result, varient_node|
|
40
40
|
varient = varient_node.css('.tech a').text.gsub('in ', '').upcase
|
41
41
|
|
42
|
-
|
43
|
-
|
42
|
+
times_url = varient_node.css('.performance-detail').map do |screening_node|
|
43
|
+
[
|
44
|
+
tz.local_to_utc(Time.parse(screening_node['title'].match(/\d+\/\d+\/\d+ \d{2}\:\d{2}/).to_s)),
|
45
|
+
"http://www.odeon.co.uk#{screening_node['href']}"
|
46
|
+
]
|
44
47
|
end
|
45
48
|
|
46
|
-
result.merge(varient =>
|
49
|
+
result.merge(varient => times_url)
|
47
50
|
end
|
48
51
|
end
|
49
52
|
end
|
data/lib/odeon_uk/screening.rb
CHANGED
@@ -3,6 +3,8 @@ module OdeonUk
|
|
3
3
|
# Public: The object representing a screening of a film on the Odeon UK website
|
4
4
|
class Screening
|
5
5
|
|
6
|
+
# Public: Returns the booking URL on the cinema website
|
7
|
+
attr_reader :booking_url
|
6
8
|
# Public: Returns the String name of the cinema
|
7
9
|
attr_reader :cinema_name
|
8
10
|
# Public: Returns the String name of the film
|
@@ -16,12 +18,12 @@ module OdeonUk
|
|
16
18
|
#
|
17
19
|
# film_name - String of the film name
|
18
20
|
# cinema_name - String of the cinema name on the Odeon website
|
19
|
-
#
|
20
|
-
# time - String representing the time of the screening (24 hour clock)
|
21
|
+
# time - Time representing the time of the screening (24 hour clock)
|
21
22
|
# varient - String representing the type of showing (e.g. 3d/baby/live)
|
22
|
-
def initialize(film_name, cinema_name,
|
23
|
+
def initialize(film_name, cinema_name, time, booking_url=nil, varient=nil)
|
23
24
|
@cinema_name, @film_name, @varient = cinema_name, film_name, varient
|
24
|
-
@
|
25
|
+
@booking_url = booking_url
|
26
|
+
@when = time.utc? ? time : TZInfo::Timezone.get('Europe/London').local_to_utc(time)
|
25
27
|
end
|
26
28
|
|
27
29
|
# Public: The Date of the screening
|
data/lib/odeon_uk/version.rb
CHANGED
data/lib/odeon_uk.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
require 'httparty'
|
2
2
|
require 'nokogiri'
|
3
3
|
require 'tzinfo'
|
4
|
-
require '
|
4
|
+
require 'tzinfo/data'
|
5
5
|
|
6
|
-
require_relative './odeon_uk/internal/film_with_screenings_parser'
|
7
6
|
require_relative './odeon_uk/version'
|
7
|
+
|
8
|
+
require_relative './odeon_uk/internal/film_with_screenings_parser'
|
9
|
+
|
8
10
|
require_relative './odeon_uk/cinema'
|
9
11
|
require_relative './odeon_uk/film'
|
10
12
|
require_relative './odeon_uk/screening'
|
data/odeon_uk.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |gem|
|
|
7
7
|
gem.name = "odeon_uk"
|
8
8
|
gem.version = OdeonUk::VERSION
|
9
9
|
gem.authors = ["Andy Croll"]
|
10
|
-
gem.email = ["
|
10
|
+
gem.email = ["andy@goodscary.com"]
|
11
11
|
gem.description = %q{An API to pull movie information from the ODEON.co.uk website}
|
12
12
|
gem.summary = %q{It's a scraper, but a nice one}
|
13
13
|
gem.homepage = "http://github.com/andycroll/odeon_uk"
|