show_listings 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d176b78bffb7f4f183113e739031441fbcd9354a
4
+ data.tar.gz: 8e6da6c1e4dad46f2f876a13bae5bb738a72f5ec
5
+ SHA512:
6
+ metadata.gz: 776a127d7ac54a88053e35bfa2934671d828360e5265214ef1ffa8932c5331ad8d7bfde0f0a1fda696266d7145baee3cd204f22b12af6d2780756a51fea8a80e
7
+ data.tar.gz: 7fe38211a3ae32f878d342ba2ef84153cc866ac13ebb84203efc40aece68054c1a575bb92d40bd40c690a1abbc6a5814203cb09f9a565924a59a045b6a5a9b27
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in new_gem.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 mmelmer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # NewGem
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/new_gem`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'new_gem'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install new_gem
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/new_gem.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "../config/show_listings.rb"
5
+
6
+ require "irb"
7
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
data/bin/show_listings ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require_relative '../lib/show_listings.rb'
5
+
6
+ ShowListings::CLI.new.call
@@ -0,0 +1 @@
1
+ require_relative '../lib/show_listings.rb'
@@ -0,0 +1,11 @@
1
+ require 'pry'
2
+ require 'open-uri'
3
+ require 'nokogiri'
4
+ require 'launchy'
5
+
6
+ module ShowListings
7
+ require_relative "show_listings/version"
8
+ require_relative "show_listings/CLI"
9
+ require_relative "show_listings/listing"
10
+ require_relative "show_listings/scraper"
11
+ end
@@ -0,0 +1,36 @@
1
+ class ShowListings::CLI
2
+
3
+ def call
4
+ puts "Would you like to check out today's shows or search by venue?"
5
+ @initial_choice = gets.strip.downcase
6
+ while !@initial_choice.include?("today") && !@initial_choice.include?("venue")
7
+ puts "\nI didn't understand your response."
8
+ puts
9
+ sleep(0.5)
10
+ call
11
+ end
12
+ if @initial_choice.include?("today")
13
+ home = Nokogiri::HTML(open("http://nyc-shows.brooklynvegan.com/events/today"))
14
+ choice = ShowListings::Scraper.new(home)
15
+ choice.today
16
+ elsif @initial_choice.include?("venue")
17
+ puts "\nWhich venue would you like to check out? (NOTE: please enter the FULL name of the venue without any punctuation!)"
18
+ venue_choice = gets.chomp.gsub(/\s/, '-')
19
+ begin
20
+ home = Nokogiri::HTML(open("http://nyc-shows.brooklynvegan.com/venues/#{venue_choice}"))
21
+ while !home.to_s.include?("ds-event-category-music")
22
+ puts "\nThere aren't any shows scheduled at #{venue_choice.split("-").each {|w| w.capitalize!}.join(" ")}."
23
+ puts
24
+ sleep(0.5)
25
+ call
26
+ end
27
+ rescue OpenURI::HTTPError
28
+ puts "\nSorry, I couldn't find that venue. Please try again."
29
+ puts
30
+ call
31
+ end
32
+ choice = ShowListings::Scraper.new(home, venue_choice)
33
+ choice.venue
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,30 @@
1
+ class ShowListings::Listing
2
+
3
+ def initialize(home, selection_number)
4
+ @home = home
5
+ @selection_number = selection_number
6
+ end
7
+
8
+ def buy_link
9
+ @home.css(".ds-event-category-music")[@selection_number-1].css(".ds-buy-tix").css("a").first["href"]
10
+ end
11
+
12
+ def info_link
13
+ "http://nyc-shows.brooklynvegan.com/" + @home.css(".ds-event-category-music")[@selection_number-1].css("a").first["href"]
14
+ end
15
+
16
+ def open_buy
17
+ puts "\nYou can buy tickets here...Goodbye!"
18
+ sleep(0.5)
19
+ Launchy.open(buy_link)
20
+ exit
21
+ end
22
+
23
+ def open_info
24
+ puts "\nOpening the page for that show...Goodbye!"
25
+ sleep(0.5)
26
+ Launchy.open(info_link)
27
+ exit
28
+ end
29
+
30
+ end
@@ -0,0 +1,133 @@
1
+ class ShowListings::Scraper
2
+
3
+ def initialize(home, venue_choice=nil)
4
+ @home = home
5
+ @venue_choice = venue_choice
6
+ end
7
+
8
+ def today
9
+ @today = true
10
+ @page = 1
11
+ @num = 1
12
+ puts "\nloading today's shows..."
13
+ puts
14
+ sleep(0.5)
15
+ numbered_list
16
+ date_choice
17
+ end
18
+
19
+ def venue
20
+ @today = false
21
+ @num = 1
22
+ @page = 2
23
+ @last_page = false
24
+ numbered_list
25
+ puts "Would you like to find out more about any of these shows? If so, enter the show's number. If you want to see more shows, type 'more'. If you're done, type 'done'."
26
+ venue_menu
27
+ end
28
+
29
+ def numbered_list
30
+ puts
31
+ @home.css('.ds-event-category-music').each_with_index do |event, idx|
32
+ if @today == true
33
+ puts "#{idx+1}. " + event.css(".ds-venue-name").text.strip
34
+ elsif @today == false
35
+ puts "#{idx+1}. " + event.css(".ds-event-date").text.strip
36
+ end
37
+ puts event.css(".ds-listing-event-title-text").text.strip
38
+ puts event.css(".ds-event-time").text.strip.split(" ").first
39
+ puts "\n"
40
+ @num +=1
41
+ end
42
+ end
43
+
44
+ def date_choice
45
+ if @home.css(".ds-paging").text.strip.include?("Next Page")
46
+ puts "If you'd like to learn about one of these shows, please enter its number. If you'd like to see more shows, type 'more'. If you're done, type 'done.'"
47
+ today_menu
48
+ else
49
+ puts "You've reached the end of today's listings. Choose the number of the show you're interested in, type 'done' if you're done, or type 'restart' to go back to the beginning of today's listings."
50
+ today_menu
51
+ end
52
+ end
53
+
54
+ def today_menu
55
+ today_entry = gets.strip.downcase
56
+ @input_int = today_entry.to_i
57
+ if today_entry.downcase == "done"
58
+ puts "\nHave a nice day - check back tomorrow!"
59
+ exit
60
+ elsif today_entry.downcase == "more"
61
+ @num +=1
62
+ @page +=1
63
+ puts "\nHere are some more listings..."
64
+ @home = Nokogiri::HTML(open"http://nyc-shows.brooklynvegan.com/events/today?page=#{@page}")
65
+ numbered_list
66
+ date_choice
67
+ elsif today_entry.downcase == "restart"
68
+ @home = Nokogiri::HTML(open("http://nyc-shows.brooklynvegan.com/events/today"))
69
+ today
70
+ elsif (0 < @input_int) && (@input_int < @num)
71
+ buy_info_choice
72
+ else
73
+ puts "I didn't understand your input. Please try again."
74
+ today_menu
75
+ end
76
+ end
77
+
78
+ def venue_menu
79
+ venue_entry = gets.chomp.downcase
80
+ @input_int = venue_entry.to_i
81
+ while (!venue_entry.include?("done") && !venue_entry.include?("more") && (@input_int == 0))
82
+ puts "I didn't understand your input. Please enter the number of the show you're interested in, enter 'more' for another page of listings, or type 'done' to exit."
83
+ venue_menu
84
+ end
85
+ if venue_entry.include?("done")
86
+ puts "\nHave a nice day - check back tomorrow!"
87
+ exit
88
+ elsif venue_entry.include?("more")
89
+ if @last_page == true
90
+ puts "\n"
91
+ puts "You've reached the end of the listings for this venue. Please enter the number of the show you're interested in, or type 'done' to exit."
92
+ venue_menu
93
+ end
94
+ puts "\nChecking for more listings..."
95
+ puts
96
+ @home = Nokogiri::HTML(open("http://nyc-shows.brooklynvegan.com/venues/#{@venue_choice}?page=#{@page}"))
97
+ numbered_list
98
+ @page +=1
99
+ if @home.css(".ds-paging").text.strip.include?("Next Page")
100
+ puts "Would you like to find out more about any of these shows? If so, enter the show's number. If you want to see more shows, type more. If you're done, type done."
101
+ venue_menu
102
+ else
103
+ puts "You have reached the end of the listings for this venue. If you'd like to learn more about one of the shows, please enter its number. If you're done, type done."
104
+ @last_page = true
105
+ venue_menu
106
+ end
107
+ elsif ((0 < @input_int) && (@input_int < @num))
108
+ buy_info_choice
109
+ elsif @input_int > 0
110
+ puts "Please enter a number between 1 and #{@num-1}"
111
+ venue_menu
112
+ end
113
+ end
114
+
115
+ def buy_info_choice
116
+ listing = ShowListings::Listing.new(@home, @input_int)
117
+ if @home.css(".ds-event-category-music")[@input_int-1].to_s.include?("ds-buy-tix")
118
+ puts "\nWould you like to buy tickets for that show or just get more info?"
119
+ buy_or_info = gets.chomp.downcase
120
+ while (!buy_or_info.include?("tix") && !buy_or_info.include?("tick") && !buy_or_info.include?("info") && !buy_or_info.include?("buy"))
121
+ puts "\nI didn't understand your input. Would you like to buy tickets for that show, or simply learn more information?"
122
+ buy_or_info = gets.chomp.downcase
123
+ end
124
+ if (buy_or_info.include?("tix") || buy_or_info.include?("tick") || buy_or_info.include?("buy"))
125
+ listing.open_buy
126
+ elsif buy_or_info.include?("info")
127
+ listing.open_info
128
+ end
129
+ else
130
+ listing.open_info
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,3 @@
1
+ module ShowListings
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'show_listings/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "show_listings"
8
+ spec.version = ShowListings::VERSION
9
+ spec.authors = ["mmelmer"]
10
+ spec.email = ["mikemelmer@gmail.com"]
11
+
12
+ spec.summary = "This gem allows you to quickly search NYC concert listings; it allows you to view the day's listings or search by venue; it also links you to info and/or ticket pages for any show."
13
+ spec.homepage = "https://github.com/mmelmer/cli-data-gem-assessment-v-000"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.11"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rspec", "~> 3.0"
32
+ spec.add_dependency "pry"
33
+ spec.add_dependency "nokogiri"
34
+ spec.add_dependency "launchy"
35
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: show_listings
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - mmelmer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
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.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: launchy
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - mikemelmer@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - bin/show_listings
114
+ - config/environment.rb
115
+ - lib/show_listings.rb
116
+ - lib/show_listings/CLI.rb
117
+ - lib/show_listings/listing.rb
118
+ - lib/show_listings/scraper.rb
119
+ - lib/show_listings/version.rb
120
+ - show_listings.gemspec
121
+ homepage: https://github.com/mmelmer/cli-data-gem-assessment-v-000
122
+ licenses:
123
+ - MIT
124
+ metadata:
125
+ allowed_push_host: https://rubygems.org
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.4.5.1
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: This gem allows you to quickly search NYC concert listings; it allows you
146
+ to view the day's listings or search by venue; it also links you to info and/or
147
+ ticket pages for any show.
148
+ test_files: []