coming_soon 0.2.5 → 0.2.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 604305adcaced9bcc6b8e032891a5f559278c8a4
4
- data.tar.gz: 80d9cd8e88840c30f272703f5bda912034cc8fa9
3
+ metadata.gz: d4609b528968b24fdb6e01b8332ffdfb995e7bc0
4
+ data.tar.gz: 19bda5075a202ea7b60257bc35dbfaea4b8ca8cc
5
5
  SHA512:
6
- metadata.gz: b49457dfdfd5e3f3368ccd611fdb13b3d0dc532574bc73dad6924bfc185f5183e32637c587eeb5ba1c6cf4855e5bb415a4af38b148d6402ba6fdc4c217b5e461
7
- data.tar.gz: 9b6347e5814e553d38859f09751fe181c0ebe696d5570978e86bd4f9a2eb19d0be712c51015e10186c4be62f717eaecebfcae5e8bc4d1b67acd4bb3a53ca99a9
6
+ metadata.gz: 495b933ecd34601133b71938ea5ea4c6bce399c9e14e9b942535a4cf68324cb7d981963e4bbf8d4515aaa0f4e1c977be069cafea70fddd21369766bca1d21a0d
7
+ data.tar.gz: 1236e4ad31516bc8ebc18c6a0d44df87531a3ce02840fc07142bf21b078e6c914ea6f24185952a0acd6e92da889f0de4a3f3f147a138ad463bb7d4ab49951e58
data/bin/coming-soon CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
+ #shebang
2
3
 
3
4
  require "bundler/setup"
4
- require "coming_soon"
5
+ require_relative "../lib/coming_soon"
5
6
 
6
7
  ComingSoon::CLI.new.call
@@ -1,6 +1,8 @@
1
1
  require 'nokogiri'
2
2
  require 'open-uri'
3
+ require 'pry'
3
4
 
4
5
  require_relative '../lib/coming_soon/version'
5
6
  require_relative '../lib/coming_soon/movie'
6
7
  require_relative '../lib/coming_soon/cli'
8
+ require_relative '../lib/coming_soon/scraper'
@@ -1,35 +1,34 @@
1
1
  class ComingSoon::CLI
2
2
 
3
3
  def call
4
- get_and_list_movies
5
-
6
- menu_selection
7
- end
8
-
9
- def get_and_list_movies
10
4
  puts ''
11
- puts ' **********************'
12
- puts ' * Movies Coming Soon *'
13
- puts ' * -------------- *'
14
- puts ' * Please wait! *'
15
- puts ' **********************'
5
+ puts ' **************************'
6
+ puts ' * Movies Coming Soon *'
7
+ puts ' * -------------- *'
8
+ puts ' * Please wait! *'
9
+ puts ' **************************'
16
10
  puts ''
17
11
 
18
- @movies = ComingSoon::Movie.movies
12
+ ComingSoon::Scraper.scrape_movies
13
+ get_and_list_movies
14
+ menu_selection
15
+ end
19
16
 
20
- @movies.each.with_index(1) do |movie, i| # set the first index to 1 and use the index number for the movie number
17
+ def get_and_list_movies
18
+
19
+ ComingSoon::Movie.movies.each.with_index(1) do |movie, i| # set the first index to 1 and use the index number for the movie number
21
20
  puts "#{i}. #{movie.name} - #{movie.start_date}"
22
21
  end
23
22
  end
24
23
 
25
24
  def list_saved_movies
26
25
  puts ''
27
- puts ' **********************'
28
- puts ' * Movies Coming Soon *'
29
- puts ' **********************'
26
+ puts ' **************************'
27
+ puts ' * Movies Coming Soon *'
28
+ puts ' **************************'
30
29
  puts ''
31
30
 
32
- @movies.each.with_index(1) do |movie, i| # set the first index to 1 and use the index number for the movie number
31
+ ComingSoon::Movie.movies.each.with_index(1) do |movie, i| # set the first index to 1 and use the index number for the movie number
33
32
  puts "#{i}. #{movie.name} - #{movie.start_date}"
34
33
  end
35
34
  end
@@ -41,11 +40,11 @@ class ComingSoon::CLI
41
40
  puts ''
42
41
  puts 'You may enter a movie number for more details or "list" to see the menu again or "exit"'
43
42
 
44
- input = gets.strip
43
+ input = gets.strip.downcase
45
44
 
46
- if input.to_i > 0 && input.to_i < @movies.size+1
47
- puts "* #{@movies[input.to_i - 1].name} - #{@movies[input.to_i - 1].start_date} *"
48
- puts @movies[input.to_i - 1].synopsis
45
+ if input.to_i > 0 && input.to_i < ComingSoon::Movie.movies.size+1
46
+ puts "* #{ComingSoon::Movie.movies[input.to_i - 1].name} - #{ComingSoon::Movie.movies[input.to_i - 1].start_date} *"
47
+ puts ComingSoon::Movie.movies[input.to_i - 1].synopsis
49
48
  elsif input == 'list'
50
49
  list_saved_movies
51
50
  elsif input == 'exit'
@@ -59,11 +58,11 @@ class ComingSoon::CLI
59
58
 
60
59
  def goodbye
61
60
  puts ''
62
- puts ' *************************'
63
- puts ' * Thank you and goodbye *'
64
- puts ' * ----------------- *'
65
- puts ' * Come back soon! *'
66
- puts ' *************************'
61
+ puts ' ***************************'
62
+ puts ' * Thank you and goodbye *'
63
+ puts ' * ----------------- *'
64
+ puts ' * Come back soon! *'
65
+ puts ' ***************************'
67
66
  puts ''
68
67
 
69
68
  exit
@@ -2,66 +2,14 @@
2
2
  class ComingSoon::Movie
3
3
  attr_accessor :name, :start_date, :url, :synopsis
4
4
 
5
- def self.movies
6
-
7
- self.scrape_movies
8
-
9
- @movies
10
-
11
- end
12
-
13
- def self.scrape_movies
14
-
15
- doc = Nokogiri::HTML(open("http://www.fandango.com/moviescomingsoon"))
16
- # name: doc.css("li.visual-item a.visual-title").text.strip
17
- # start_date: doc.css("li.visual-item span").text
18
- # url: doc.css("li.visual-item a").attribute("href").value
19
-
20
- movie_list = doc.css("li.visual-item")
21
- @movies = []
22
- count = 1
5
+ @@movies = []
23
6
 
24
- movie_list.each do |movie|
25
- @soon = self.new
26
- @soon.name = movie.css("a.visual-title").text.strip
27
- @soon.start_date = movie.css("span").text
28
- @soon.url = movie.css("a").attribute("href").value
7
+ def initialize
8
+ @@movies << self
9
+ end
29
10
 
30
- self.scrape_synopsis
31
-
32
- @movies << @soon
33
-
34
- count+=1
35
- if count > 20 # Displays only 20 movies
36
- break
37
- end
38
- end
39
-
40
- end
41
-
42
- def self.scrape_synopsis
43
-
44
- redirect_failed = false
45
-
46
- begin
47
- @doc_synop1 = Nokogiri::HTML(open(@soon.url)) # Uses the HTTP 'movieoverview' url
48
- rescue
49
- redirect_failed = true # An HTTP to HTTPS redirect failed
50
- end
51
-
52
- if !@doc_synop1.css("a.movie-synopsis-link").any? && !redirect_failed &&
53
- @doc_synop1.css("span#SynopsisTextLabel").any?
54
- # If not a redirect failure and a READ FULL SYNOPSIS link is not
55
- # present and any text is available, use the text for the synopsis
56
- @soon.synopsis = @doc_synop1.css("span#SynopsisTextLabel").text
57
- else
58
- # Scrape the synopsis using the HTTP 'plotsummary' url
59
- # This is also executed after an HTTP to HTTPS redirect failed
60
- synop_url = @soon.url.sub(/movieoverview/, 'plotsummary')
61
- doc_synop2 = Nokogiri::HTML(open(synop_url))
62
- @soon.synopsis = doc_synop2.css("p.subpage-descriptive-content").text
63
- end
64
-
65
- end
11
+ def self.movies
12
+ @@movies
13
+ end
66
14
 
67
15
  end
@@ -0,0 +1,54 @@
1
+ class ComingSoon::Scraper
2
+
3
+ def self.scrape_movies
4
+
5
+ doc = Nokogiri::HTML(open("http://www.fandango.com/moviescomingsoon"))
6
+ # name: doc.css("li.visual-item a.visual-title").text.strip
7
+ # start_date: doc.css("li.visual-item span").text
8
+ # url: doc.css("li.visual-item a").attribute("href").value
9
+
10
+ movie_list = doc.css("li.visual-item")
11
+
12
+ count = 0
13
+
14
+ movie_list.each do |movie|
15
+ soon = ComingSoon::Movie.new
16
+ soon.name = movie.css("a.visual-title").text.strip
17
+ soon.start_date = movie.css("span").text
18
+ soon.url = movie.css("a").attribute("href").value
19
+
20
+ self.scrape_synopsis(soon)
21
+
22
+ count+=1
23
+ if count > 19 # Displays only 20 movies
24
+ break
25
+ end
26
+ end
27
+
28
+ end
29
+
30
+ def self.scrape_synopsis(soon)
31
+
32
+ redirect_failed = false
33
+
34
+ begin
35
+ @doc_synop1 = Nokogiri::HTML(open(soon.url)) # Uses the HTTP 'movieoverview' url
36
+ rescue
37
+ redirect_failed = true # An HTTP to HTTPS redirect failed
38
+ end
39
+
40
+ if !@doc_synop1.css("a.movie-synopsis-link").any? && !redirect_failed &&
41
+ @doc_synop1.css("span#SynopsisTextLabel").any?
42
+ # If not a redirect failure and a READ FULL SYNOPSIS link is not
43
+ # present and any text is available, use the text for the synopsis
44
+ soon.synopsis = @doc_synop1.css("span#SynopsisTextLabel").text
45
+ else
46
+ # Scrape the synopsis using the HTTP 'plotsummary' url
47
+ # This is also executed after an HTTP to HTTPS redirect failed
48
+ synop_url = soon.url.sub(/movieoverview/, 'plotsummary')
49
+ doc_synop2 = Nokogiri::HTML(open(synop_url))
50
+ soon.synopsis = doc_synop2.css("p.subpage-descriptive-content").text
51
+ end
52
+
53
+ end
54
+ end
@@ -1,4 +1,4 @@
1
1
 
2
2
  module ComingSoon
3
- VERSION = "0.2.5"
3
+ VERSION = "0.2.6"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coming_soon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Terry Blue
@@ -103,6 +103,7 @@ files:
103
103
  - lib/coming_soon.rb
104
104
  - lib/coming_soon/cli.rb
105
105
  - lib/coming_soon/movie.rb
106
+ - lib/coming_soon/scraper.rb
106
107
  - lib/coming_soon/version.rb
107
108
  - notes.md
108
109
  - spec.md