picturehouse_uk 3.0.14 → 5.0.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.
Files changed (63) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ci.yml +26 -0
  3. data/.github/workflows/release.yml +26 -0
  4. data/.gitignore +1 -0
  5. data/.ruby-version +1 -0
  6. data/CHANGELOG.md +44 -0
  7. data/LICENSE +617 -0
  8. data/README.md +5 -4
  9. data/Rakefile +12 -0
  10. data/lib/picturehouse_uk/cinema.rb +152 -127
  11. data/lib/picturehouse_uk/internal/api.rb +42 -0
  12. data/lib/picturehouse_uk/internal/parser/address.rb +36 -9
  13. data/lib/picturehouse_uk/internal/parser/screenings.rb +89 -95
  14. data/lib/picturehouse_uk/internal/title_sanitizer.rb +61 -65
  15. data/lib/picturehouse_uk/internal/website.rb +10 -12
  16. data/lib/picturehouse_uk/performance.rb +60 -0
  17. data/lib/picturehouse_uk/version.rb +2 -2
  18. data/lib/picturehouse_uk.rb +3 -4
  19. data/picturehouse_uk.gemspec +5 -7
  20. data/rake/fixture_creator.rb +62 -0
  21. data/test/fixtures/cinemas.html +4262 -0
  22. data/test/fixtures/duke-of-york-s-picturehouse/cinema.html +6187 -0
  23. data/test/fixtures/duke-of-york-s-picturehouse/get_movies.json +120552 -0
  24. data/test/fixtures/duke-of-york-s-picturehouse/information.html +3725 -0
  25. data/test/fixtures/duke-s-at-komedia/cinema.html +6138 -0
  26. data/test/fixtures/duke-s-at-komedia/get_movies.json +112 -0
  27. data/test/fixtures/duke-s-at-komedia/information.html +3690 -0
  28. data/test/fixtures/home.html +6236 -565
  29. data/test/fixtures/phoenix-picturehouse/cinema.html +6089 -0
  30. data/test/fixtures/phoenix-picturehouse/get_movies.json +120552 -0
  31. data/test/fixtures/phoenix-picturehouse/information.html +3630 -0
  32. data/test/lib/picturehouse_uk/cinema_test.rb +113 -142
  33. data/test/lib/picturehouse_uk/internal/api_test.rb +92 -0
  34. data/test/lib/picturehouse_uk/internal/parser/{address_parser_test.rb → address_test.rb} +11 -11
  35. data/test/lib/picturehouse_uk/internal/parser/screenings_test.rb +100 -48
  36. data/test/lib/picturehouse_uk/internal/title_sanitizer_test.rb +48 -48
  37. data/test/lib/picturehouse_uk/internal/website_test.rb +15 -31
  38. data/test/lib/picturehouse_uk/performance_test.rb +197 -0
  39. data/test/lib/picturehouse_uk/version_test.rb +1 -1
  40. data/test/live/integration_test.rb +15 -32
  41. data/test/support/fake_api.rb +16 -0
  42. data/test/support/fake_website.rb +24 -0
  43. data/test/test_helper.rb +13 -2
  44. metadata +52 -67
  45. data/.rdoc_options +0 -16
  46. data/.travis.yml +0 -5
  47. data/lib/picturehouse_uk/film.rb +0 -59
  48. data/lib/picturehouse_uk/screening.rb +0 -70
  49. data/test/fixture_updater.rb +0 -73
  50. data/test/fixtures/cinema/Duke_Of_Yorks.html +0 -2984
  51. data/test/fixtures/cinema/Dukes_At_Komedia.html +0 -5518
  52. data/test/fixtures/cinema/National_Media_Museum.html +0 -10266
  53. data/test/fixtures/cinema/Phoenix_Picturehouse.html +0 -5202
  54. data/test/fixtures/info/Duke_Of_Yorks.html +0 -549
  55. data/test/fixtures/info/Dukes_At_Komedia.html +0 -537
  56. data/test/fixtures/info/Phoenix_Picturehouse.html +0 -553
  57. data/test/fixtures/whats_on/Duke_Of_Yorks.html +0 -2737
  58. data/test/fixtures/whats_on/Dukes_At_Komedia.html +0 -5132
  59. data/test/fixtures/whats_on/National_Media_Museum.html +0 -9690
  60. data/test/fixtures/whats_on/Phoenix_Picturehouse.html +0 -4916
  61. data/test/lib/picturehouse_uk/film_test.rb +0 -141
  62. data/test/lib/picturehouse_uk/screening_test.rb +0 -181
  63. /data/{LICENSE.txt → COMM-LICENSE} +0 -0
@@ -2,75 +2,71 @@ module PicturehouseUk
2
2
  # @api private
3
3
  module Internal
4
4
  # Sanitize and standardize film titles
5
- class TitleSanitizer
6
- # strings and regex to be removed
7
- REMOVE = [
8
- /\s\[(AS LIVE:\s*)?[ACPGU1258]+\]/, # regular certificate
9
- /\s\[R18\]/, # R18
10
- /\s+\(?[23][dD]\)?/, # 2d or 3d from title
11
- /\bIMAX\b/i, # imax from title
12
- /\s\[NO CERT\]/, # no certificate
13
- /\s\[TBC\]/, # tbc
14
- /\s\[N\/A\]/i, # n/a
15
- /\s\(Theatre\)/i, # (theatre)
16
- /\s\[\]/, # blank certificate
17
- /ourscreen\: /, # ourscreen
18
- /\s\(Re(\: \d{0,4})?\)/i, # Re-release
19
- /\s\[CERT TBC\]/, # certificate TBC
20
- /\s?\-\s?autism.*ing\s?/i, # austim screening
21
- /\s?\+\s?Q\&A\.?/i, # +Q&A
22
- /KIDS CLUB\s*/i, # kids club
23
- /DISCOVER TUE(sday\:)*\s*/i, # discover tue
24
- /FREE Screening\s*-\s*/i, # free screening
25
- /\s*-?\s*Big Scream\s*-?\s*/i, # big scream
26
- /\*?HOH Subtitled\*?/i, # subtitled
27
- /\s*\-?\s*Reminiscence/i, # reminiscence
28
- /\s*\-?\s*\(?Re\-issue\)?/i, # reissue
29
- /\s*-?\s*Kids\'? Club\s*-?\s*/, # kids club
30
- /\s*plus Q\&A.*/i, # extended Q&A
31
- /Cinemania\s*[\:\-]/i, # cinemania
32
- /\@\s*komedia/i, # @ komedia
33
- /\s*\+ panel.*/i, # panel
34
- /toddler time\s*\:*\-*/i, # toddler time
35
- /\(.*\d{4}\)/, # year or captured year
36
- /\bsingalong\b/i, # singalong
37
- /\s+\-?\s*Parents \& Babies/i, # parents and babies
38
- /Subtitled\:*\s*/i, # subtitled
39
- /\(?live\)?\z/i, # live
40
- ]
5
+ class TitleSanitizer < Cinebase::TitleSanitizer
6
+ # @!method initialize(title)
7
+ # Constructor
8
+ # @param [String] title a film title
9
+ # @return [CineworldUk::Internal::TitleSanitizer]
41
10
 
42
- # regexes and their replacements
43
- REPLACE = {
44
- /Met\.? Encore:\s*(.*)/ => 'Met Opera: ',
45
- /Met\.? Opera:\s*(.*)/ => 'Met Opera: ',
46
- /National Theatre:\s*(.*)/ => 'NT Live: ',
47
- /NT Encore:\s*(.*)/ => 'NT Live: ',
48
- /NT Live:\s*(.*)/ => 'NT Live: ',
49
- /ROH\.? Live:\s*(.*)/ => 'Royal Opera House: ',
50
- /ROH\.? Encore:\s*(.*)/ => 'Royal Opera House: ',
51
- /RSC\.? Live:\s*(.*)/ => 'Royal Shakespeare Company: ',
52
- /RSC\.? Encore:\s*(.*)/ => 'Royal Shakespeare Company: ',
53
- /(.*) \(Bolshoi Ballet\)/ => 'Bolshoi Ballet: '
54
- }
11
+ # @!method sanitized
12
+ # sanitized and standardized title
13
+ # @return [String] sanitised title
14
+
15
+ private
55
16
 
56
- # @param [String] title a film title
57
- def initialize(title)
58
- @title = title
17
+ # strings and regex to be removed
18
+ def remove
19
+ [
20
+ /\s\[(AS LIVE:\s*)?[ACPGU1258]+\]/, # regular certificate
21
+ /\s\[R18\]/, # R18
22
+ /\s+\(?[23][dD]\)?/, # 2d or 3d from title
23
+ /\bIMAX\b/i, # imax from title
24
+ /\s\[NO CERT\]/, # no certificate
25
+ /\s\[TBC\]/, # tbc
26
+ /\s\[N\/A\]/i, # n/a
27
+ /\s\(Theatre\)/i, # (theatre)
28
+ /\s\[\]/, # blank certificate
29
+ /ourscreen\: /, # ourscreen
30
+ /\s\(Re(\: \d{0,4})?\)/i, # Re-release
31
+ /\s\[CERT TBC\]/, # certificate TBC
32
+ /\s?\-\s?autism.*ing\s?/i, # austim screening
33
+ /\s?\+\s?Q\&(amp;)*A\.?/i, # +Q&A
34
+ /KIDS CLUB\s*/i, # kids club
35
+ /DISCOVER TUE(sday\:)*\s*/i, # discover tue
36
+ /FREE Screening\s*-\s*/i, # free screening
37
+ /\s*-?\s*Big Scream\s*-?\s*/i, # big scream
38
+ /\*?HOH Subtitled\*?/i, # subtitled
39
+ /\s*\-?\s*Reminiscence/i, # reminiscence
40
+ /\s*\-?\s*\(?Re\-issue\)?/i, # reissue
41
+ /\s*-?\s*Kids\'? Club\s*-?\s*/, # kids club
42
+ /\s*plus Q\&A.*/i, # extended Q&A
43
+ /Cinemania\s*[\:\-]/i, # cinemania
44
+ /\@\s*komedia/i, # @ komedia
45
+ /\s*\+ panel.*/i, # panel
46
+ /toddler time\s*\:*\-*/i, # toddler time
47
+ /\(.*\d{4}\)/, # year or captured year
48
+ /\bsingalong\b/i, # singalong
49
+ /\s+\-?\s*Parents \& Babies/i, # parents and babies
50
+ /Subtitled\:*\s*/i, # subtitled
51
+ /\(?live\)?\z/i, # live
52
+ /amp\;/i
53
+ ]
59
54
  end
60
55
 
61
- # sanitized and standardized title
62
- # @return [String] title
63
- def sanitized
64
- @sanitzed ||= begin
65
- sanitized = @title.gsub('&amp;', '&')
66
- REMOVE.each do |pattern|
67
- sanitized.gsub! pattern, ''
68
- end
69
- REPLACE.each do |pattern, prefix|
70
- sanitized.gsub!(pattern) { |_| prefix + $1 }
71
- end
72
- sanitized.squeeze(' ').strip
73
- end
56
+ # regexes and their replacements
57
+ def replace
58
+ {
59
+ /Met\.? Encore:\s*(.*)/ => 'Met Opera: ',
60
+ /Met\.? Opera:\s*(.*)/ => 'Met Opera: ',
61
+ /National Theatre:\s*(.*)/ => 'NT Live: ',
62
+ /NT Encore:\s*(.*)/ => 'NT Live: ',
63
+ /NT Live:\s*(.*)/ => 'NT Live: ',
64
+ /ROH\.? Live:\s*(.*)/ => 'Royal Opera House: ',
65
+ /ROH\.? Encore:\s*(.*)/ => 'Royal Opera House: ',
66
+ /RSC\.? Live:\s*(.*)/ => 'Royal Shakespeare Company: ',
67
+ /RSC\.? Encore:\s*(.*)/ => 'Royal Shakespeare Company: ',
68
+ /(.*) \(Bolshoi Ballet\)/ => 'Bolshoi Ballet: '
69
+ }
74
70
  end
75
71
  end
76
72
  end
@@ -12,18 +12,10 @@ module PicturehouseUk
12
12
  get("cinema/#{id}")
13
13
  end
14
14
 
15
- # get the cinema screenings page for passed id
16
- # @return [String]
17
- def whats_on(id)
18
- get("cinema/#{id}/Whats_On")
19
- rescue OpenURI::HTTPError
20
- ''
21
- end
22
-
23
15
  # get the cinema contact information page for passed id
24
16
  # @return [String]
25
- def info(id)
26
- get("cinema/info/#{id}")
17
+ def information(id)
18
+ get("cinema/#{id}/information")
27
19
  rescue OpenURI::HTTPError
28
20
  ''
29
21
  end
@@ -34,12 +26,18 @@ module PicturehouseUk
34
26
  get(nil)
35
27
  end
36
28
 
29
+ # get the cinemas listing page
30
+ # @return [String]
31
+ def cinemas
32
+ get("cinema")
33
+ end
34
+
37
35
  private
38
36
 
39
37
  def get(path)
40
38
  # SSL verification doesn't work on picturehouses.com
41
- open("https://www.picturehouses.com/#{path}",
42
- ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE).read
39
+ URI.open("https://www.picturehouses.com/#{path}",
40
+ ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE).read
43
41
  end
44
42
  end
45
43
  end
@@ -0,0 +1,60 @@
1
+ module PicturehouseUk
2
+ # A single screening of a film on the Picturehouse UK website
3
+ class Performance < Cinebase::Performance
4
+ # @!attribute [r] booking_url
5
+ # @return [String] the booking URL on the cinema website
6
+ # @!attribute [r] cinema_name
7
+ # @return [String] the cinema name
8
+ # @!attribute [r] cinema_id
9
+ # @return [String] the cinema id
10
+ # @!attribute [r] dimension
11
+ # @return [String] 2d or 3d
12
+ # @!attribute [r] film_name
13
+ # @return [String] the film name
14
+
15
+ # @!method initialize(options)
16
+ # @param [Hash] options options hash
17
+ # @option options [String] :booking_url (nil) buying url for the screening
18
+ # @option options [String] :cinema_name name of the cinema
19
+ # @option options [String] :cinema_id website id of the cinema
20
+ # @option options [String] :dimension ('2d') dimension of the screening
21
+ # @option options [String] :film_name name of the film
22
+ # @option options [Time] :starting_at listed start time of the performance
23
+
24
+ # Screenings at a single cinema
25
+ # @param [String] cinema_id the id of the cinema
26
+ # @return [Array<PicturehouseUk::Screening>]
27
+ def self.at(cinema_id)
28
+ screenings(cinema_id).map do |attributes|
29
+ new cinema_hash(cinema_id).merge(attributes)
30
+ end.uniq
31
+ end
32
+
33
+ # @!method showing_on
34
+ # The date of the screening
35
+ # @return [Date]
36
+
37
+ # @!method starting_at
38
+ # UTC time of the screening
39
+ # @return [Time]
40
+
41
+ # @!method variant
42
+ # The kinds of screening (IMAX, kids, baby, senior)
43
+ # @return <Array[String]>
44
+
45
+ # private
46
+
47
+ def self.cinema_hash(cinema_id)
48
+ {
49
+ cinema_id: cinema_id,
50
+ cinema_name: PicturehouseUk::Cinema.new(cinema_id).name
51
+ }
52
+ end
53
+ private_class_method :cinema_hash
54
+
55
+ def self.screenings(cinema_id)
56
+ PicturehouseUk::Internal::Parser::Screenings.new(cinema_id).to_a
57
+ end
58
+ private_class_method :screenings
59
+ end
60
+ end
@@ -1,6 +1,6 @@
1
1
  # Ruby interface for http://www.picturehouses.co.uk
2
- # @version 3.0.14
2
+ # @version 5.0.0
3
3
  module PicturehouseUk
4
4
  # Gem version
5
- VERSION = '3.0.14'
5
+ VERSION = '5.0.0'.freeze
6
6
  end
@@ -1,17 +1,16 @@
1
+ require 'cinebase'
1
2
  require 'nokogiri'
2
- require 'tzinfo'
3
- require 'tzinfo/data'
4
3
 
5
4
  require_relative './picturehouse_uk/version'
6
5
 
6
+ require_relative './picturehouse_uk/internal/api'
7
7
  require_relative './picturehouse_uk/internal/parser/address'
8
8
  require_relative './picturehouse_uk/internal/parser/screenings'
9
9
  require_relative './picturehouse_uk/internal/title_sanitizer'
10
10
  require_relative './picturehouse_uk/internal/website'
11
11
 
12
12
  require_relative './picturehouse_uk/cinema'
13
- require_relative './picturehouse_uk/film'
14
- require_relative './picturehouse_uk/screening'
13
+ require_relative './picturehouse_uk/performance'
15
14
 
16
15
  module PicturehouseUk
17
16
  end
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  lib = File.expand_path('../lib', __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'picturehouse_uk/version'
@@ -8,22 +7,21 @@ Gem::Specification.new do |spec|
8
7
  spec.version = PicturehouseUk::VERSION
9
8
  spec.authors = ['Andy Croll']
10
9
  spec.email = ['andy@goodscary.com']
11
- spec.description = 'An API to pull movie information from the picturehouse.co.uk website'
10
+ spec.description = 'API pulling information from picturehouse.com'
12
11
  spec.summary = "It's a scraper, but a nice one"
13
12
  spec.homepage = ''
14
- spec.license = 'MIT'
13
+ spec.licenses = %w(AGPL MIT)
15
14
 
16
- spec.files = `git ls-files`.split($/)
15
+ spec.files = `git ls-files`.split("\n")
17
16
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
18
  spec.require_paths = ['lib']
20
19
 
21
- spec.add_development_dependency 'bundler', '~> 1.3'
22
20
  spec.add_development_dependency 'minitest-reporters'
23
21
  spec.add_development_dependency 'rake'
22
+ spec.add_development_dependency 'simplecov'
24
23
  spec.add_development_dependency 'webmock'
25
24
 
25
+ spec.add_runtime_dependency 'cinebase', '~> 3.0'
26
26
  spec.add_runtime_dependency 'nokogiri'
27
- spec.add_runtime_dependency 'tzinfo'
28
- spec.add_runtime_dependency 'tzinfo-data'
29
27
  end
@@ -0,0 +1,62 @@
1
+ # Create fitures from the live website
2
+ class FixtureCreator
3
+ def cinema(cinema_id)
4
+ %i(cinema information).each do |action|
5
+ write_fixture_for_cinema(cinema_id, action)
6
+ end
7
+ write_api_fixture_for_cinema(cinema_id)
8
+ end
9
+
10
+ def home
11
+ write_fixture(:home)
12
+ end
13
+
14
+ def cinemas
15
+ write_fixture(:cinemas)
16
+ end
17
+
18
+ private
19
+
20
+ def fixture(name)
21
+ File.expand_path("#{fixture_path}/#{name}.html", __FILE__)
22
+ end
23
+
24
+ def json_fixture(name)
25
+ File.expand_path("#{fixture_path}/#{name}.json", __FILE__)
26
+ end
27
+
28
+ def fixture_path
29
+ '../../test/fixtures'
30
+ end
31
+
32
+ def log(message)
33
+ puts "Create API fixture: #{message}"
34
+ end
35
+
36
+ def write_fixture_for_cinema(cinema_id, kind)
37
+ FileUtils.mkdir_p File.expand_path("#{fixture_path}/#{cinema_id}", __FILE__)
38
+ text = "#{cinema_id}/#{kind}"
39
+ File.open(fixture(text), 'w+') do |file|
40
+ log(text)
41
+ file.write PicturehouseUk::Internal::Website.new.send(kind, cinema_id)
42
+ end
43
+ end
44
+
45
+ def write_api_fixture_for_cinema(cinema_id)
46
+ require 'json'
47
+ FileUtils.mkdir_p File.expand_path("#{fixture_path}/#{cinema_id}", __FILE__)
48
+ text = "#{cinema_id}/get_movies"
49
+ File.open(json_fixture(text), 'w+') do |file|
50
+ log(text)
51
+ data = PicturehouseUk::Internal::Api.new.get_movies(cinema_id)
52
+ file.write JSON.pretty_generate(data)
53
+ end
54
+ end
55
+
56
+ def write_fixture(kind)
57
+ File.open(fixture(kind), 'w+') do |file|
58
+ log(kind)
59
+ file.write PicturehouseUk::Internal::Website.new.send(kind.to_sym)
60
+ end
61
+ end
62
+ end