From def65482512665c081c7e8860bcd2f51b713fb38 Mon Sep 17 00:00:00 2001 From: dwisecar Date: Wed, 2 Dec 2020 16:06:01 -0800 Subject: [PATCH 1/3] start --- Gemfile.lock | 4 +- README.md | 109 +++++++++++++++++++++++++++++++++++++++++++ bin/run.rb | 5 +- lib/get_requester.rb | 19 ++++++++ 4 files changed, 132 insertions(+), 5 deletions(-) create mode 100644 lib/get_requester.rb diff --git a/Gemfile.lock b/Gemfile.lock index 9589226d..e0bcebd4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -36,7 +36,7 @@ GEM activerecord (>= 3.2) sinatra (>= 1.0) slop (3.6.0) - sqlite3 (1.3.13) + sqlite3 (1.4) thread_safe (0.3.6) tilt (2.0.10) tzinfo (1.2.7) @@ -53,4 +53,4 @@ DEPENDENCIES sqlite3 BUNDLED WITH - 1.14.6 + 2.1.4 diff --git a/README.md b/README.md index b75f6185..762412ce 100644 --- a/README.md +++ b/README.md @@ -50,10 +50,119 @@ Projects need to be approved prior to launching into them, so take some time to - Present any code you would like to highlight. 7. *OPTIONAL, BUT RECOMMENDED*: Write a blog post about the project and process. + + + + + +### Option One - Data Analytics Project +1. Access a Sqlite3 Database using ActiveRecord. + +2. You should have at minimum three models including one join model. This means you must have a many-to-many relationship. +User >--- Ticket ---< Event ---< Venue ---< City + +User has_many Tickets +User has_many Events through Tickets +Ticket belongs to one user +Ticket belongs to one event +Event has_one venue +Event has_one City through Venue +Event has many tickets +Event has many users through tickets +Venue has many events +Venue belongs to one city + +3. You should seed your database using data that you collect either from a CSV, a website by scraping, or an API. +Ticket master API +API Key: QATrioQ3vEzlLyBebumHRHuNBfT39vrZ +API call format: https://app.ticketmaster.com/{package}/{version}/{resource}.json?apikey=**{API key} + -package: discovery? + -version: v2? + -resources: event, attraction, classification, venue... + +4. Your models should have methods that answer interesting questions about the data. For example, if you've collected info about movie reviews, what is the most popular movie? What movie has the most reviews? +I want to see all events in time frame in certain city +I want to see what types of events are happening within a time frame +I want to see whats happening within a price range +I want to see a record of the events I've been too +I want to see upcoming events in a similar genres to ones I've attended be +I want to see if the event I had a ticket for has been cancelled +I want to see when my favorite band is coming to my city + +5. You should provide a CLI to display the return values of your interesting methods. +? + +6. Use good OO design patterns. You should have separate classes for your models and CLI interface. + + +User CLI options + -User starts by entering location + -takes a string of city and checks if valid in database + -if no, puts out "City not found" + -if yes, store city in args hash, start next method for date + + 0. search by attraction name. + 1. search by date MM/DD/YYYY + 0-9 reserved for results + -if 0-9 puts event details with y to buy and n to go back + F. filter option menu which puts out which keys to input for another filter + D. to enter a date into the search and filter results by it + P. to enter a price into the search and filter results by it + G. to enter and filter by genre + 2.search by price + 0-9 reserved for results + F. filter option menu which puts out which keys to input for another filter + D. to enter a date into the search and filter results by it + P. to enter a price into the search and filter results by it + G. to enter and filter by genre + 3. search by genre + 0-9 reserved for results + F. filter option menu which puts out which keys to input for another filter + D. to enter a date into the search and filter results by it + P. to enter a price into the search and filter results by it + G. to enter and filter by genre + + -date input is string + -check if valid, if not return to last page with puts error message + -if valid, + + + -Entering B goes back to previous page + -See all Events available by date + -see all Events available by price range + -user sees list of events, can select one with 0-9 input + -sees event, venue, price, then Y/N to purchase ticket + -Y takes them back to main page + -N goes back one level + -purchase ticket for event + -See events they have tickets for + -see events they have tickets for by date + -See events they have that are not cancelled + + + +User class + -instance variables: name + +Ticket class + -instance variables: user_id, event_id + +Event + -Location + -price range + -attraction name + -genre + + + + --- ### Common Questions: - How do I turn off my SQL logger? ```ruby # in config/environment.rb add this line: ActiveRecord::Base.logger = nil + + + ``` diff --git a/bin/run.rb b/bin/run.rb index cf08c338..58d56346 100644 --- a/bin/run.rb +++ b/bin/run.rb @@ -1,5 +1,4 @@ require_relative '../config/environment' - - -puts "HELLO WORLD" +info = GetRequester.new("https://app.ticketmaster.com/discovery/v2/events.json?apikey=QATrioQ3vEzlLyBebumHRHuNBfT39vrZ") +puts info.parse_json diff --git a/lib/get_requester.rb b/lib/get_requester.rb new file mode 100644 index 00000000..1afb4aa1 --- /dev/null +++ b/lib/get_requester.rb @@ -0,0 +1,19 @@ +require 'open-uri' +require 'net/http' +require 'json' + +class GetRequester + def initialize(url) + @url = url + end + + def get_response_body + uri = URI.parse(@url) + response = Net::HTTP.get_response(uri) + response.body + end + + def parse_json + JSON.parse(self.get_response_body) + end +end \ No newline at end of file From c9172f005aade3334410b085f0936ce9f066932a Mon Sep 17 00:00:00 2001 From: dwisecar Date: Wed, 2 Dec 2020 18:04:02 -0800 Subject: [PATCH 2/3] end day one --- bin/run.rb | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/bin/run.rb b/bin/run.rb index 58d56346..1da40d25 100644 --- a/bin/run.rb +++ b/bin/run.rb @@ -1,4 +1,32 @@ require_relative '../config/environment' -info = GetRequester.new("https://app.ticketmaster.com/discovery/v2/events.json?apikey=QATrioQ3vEzlLyBebumHRHuNBfT39vrZ") -puts info.parse_json +info = GetRequester.new("https://app.ticketmaster.com/discovery/v2/events.json?city=Seattle&size=1&apikey=QATrioQ3vEzlLyBebumHRHuNBfT39vrZ").parse_json +# puts info["_embedded"]["events"][0]["name"] +# puts info["_embedded"]["events"][0]["classifications"][0]["subGenre"]["name"] +# puts info["_embedded"]["events"][0]["dates"]["start"]["localDate"] +# puts info["_embedded"]["events"][0]["_embedded"]["venues"][0]["name"] +# puts info["_embedded"]["events"][0]["dates"]["status"]["code"] + +def search_by_city + puts "enter a city" + city = gets + info = GetRequester.new("https://app.ticketmaster.com/discovery/v2/events.json?city=#{city}&size=10&apikey=QATrioQ3vEzlLyBebumHRHuNBfT39vrZ").parse_json + puts event_details(info) +end + +def cancelled_events_count + info = GetRequester.new("https://app.ticketmaster.com/discovery/v2/events.json?apikey=QATrioQ3vEzlLyBebumHRHuNBfT39vrZ").parse_json + info["_embedded"]["events"].select {|e|e["dates"]["status"]["code"] = "offsale"}.size +end + +def event_details(info) + events = [] + i = 1 + info["_embedded"]["events"].each do |event| + events << "#{i}. #{event["name"]} - #{event["dates"]["start"]["localDate"]} - #{event["_embedded"]["venues"][0]["name"]} - #{event["classifications"][0]["subGenre"]["name"]}" + i+=1 + end + events +end + +#search_by_city \ No newline at end of file From f84bf50c51d18a9cc7ff171b6def8ac69e5bd012 Mon Sep 17 00:00:00 2001 From: dwisecar Date: Thu, 3 Dec 2020 09:19:35 -0800 Subject: [PATCH 3/3] created models --- README.md | 4 +--- app/models/event.rb | 4 ++++ app/models/ticket.rb | 4 ++++ app/models/user.rb | 4 ++++ bin/run.rb | 11 ++++++----- 5 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 app/models/event.rb create mode 100644 app/models/ticket.rb create mode 100644 app/models/user.rb diff --git a/README.md b/README.md index 762412ce..934a1ea9 100644 --- a/README.md +++ b/README.md @@ -122,9 +122,7 @@ User CLI options P. to enter a price into the search and filter results by it G. to enter and filter by genre - -date input is string - -check if valid, if not return to last page with puts error message - -if valid, + -Entering B goes back to previous page diff --git a/app/models/event.rb b/app/models/event.rb new file mode 100644 index 00000000..bbff938b --- /dev/null +++ b/app/models/event.rb @@ -0,0 +1,4 @@ +class Event < ActiveRecord::Base + has_many :tickets + has_many :users, through: :tickets +end \ No newline at end of file diff --git a/app/models/ticket.rb b/app/models/ticket.rb new file mode 100644 index 00000000..b318a2f6 --- /dev/null +++ b/app/models/ticket.rb @@ -0,0 +1,4 @@ +class Ticket < ActiveRecord::Base + belongs_to :user + belongs_to :event +end \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 00000000..14b5c44e --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,4 @@ +class User < ActiveRecord::Base + has_many :tickets + has_many :events, through: :tickets +end \ No newline at end of file diff --git a/bin/run.rb b/bin/run.rb index 1da40d25..21762890 100644 --- a/bin/run.rb +++ b/bin/run.rb @@ -7,16 +7,17 @@ # puts info["_embedded"]["events"][0]["_embedded"]["venues"][0]["name"] # puts info["_embedded"]["events"][0]["dates"]["status"]["code"] + def search_by_city puts "enter a city" city = gets - info = GetRequester.new("https://app.ticketmaster.com/discovery/v2/events.json?city=#{city}&size=10&apikey=QATrioQ3vEzlLyBebumHRHuNBfT39vrZ").parse_json + info = GetRequester.new("https://app.ticketmaster.com/discovery/v2/events.json?city=#{city}&apikey=QATrioQ3vEzlLyBebumHRHuNBfT39vrZ").parse_json puts event_details(info) end -def cancelled_events_count - info = GetRequester.new("https://app.ticketmaster.com/discovery/v2/events.json?apikey=QATrioQ3vEzlLyBebumHRHuNBfT39vrZ").parse_json - info["_embedded"]["events"].select {|e|e["dates"]["status"]["code"] = "offsale"}.size +def events_count + info = GetRequester.new("https://app.ticketmaster.com/discovery/v2/events.json?country=usa&apikey=QATrioQ3vEzlLyBebumHRHuNBfT39vrZ").parse_json + info["_embedded"]["events"].count end def event_details(info) @@ -29,4 +30,4 @@ def event_details(info) events end -#search_by_city \ No newline at end of file +search_by_city