Class: Exhibitionist::Shows
- Inherits:
-
Object
- Object
- Exhibitionist::Shows
- Defined in:
- lib/exhibitionist/shows.rb
Constant Summary collapse
- @@all_shows =
[]
Instance Attribute Summary collapse
-
#closing_date ⇒ Object
Returns the value of attribute closing_date.
-
#dates ⇒ Object
Returns the value of attribute dates.
-
#days_left ⇒ Object
Returns the value of attribute days_left.
-
#museum ⇒ Object
Returns the value of attribute museum.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
- .all ⇒ Object
- .brooklyn_scraper ⇒ Object
- .met_scraper ⇒ Object
- .moma_scraper ⇒ Object
- .new_museum_scraper ⇒ Object
- .scrape_all ⇒ Object
- .sort_by_closing_date ⇒ Object
- .whitney_scraper ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#closing_date ⇒ Object
Returns the value of attribute closing_date.
4 5 6 |
# File 'lib/exhibitionist/shows.rb', line 4 def closing_date @closing_date end |
#dates ⇒ Object
Returns the value of attribute dates.
4 5 6 |
# File 'lib/exhibitionist/shows.rb', line 4 def dates @dates end |
#days_left ⇒ Object
Returns the value of attribute days_left.
4 5 6 |
# File 'lib/exhibitionist/shows.rb', line 4 def days_left @days_left end |
#museum ⇒ Object
Returns the value of attribute museum.
4 5 6 |
# File 'lib/exhibitionist/shows.rb', line 4 def museum @museum end |
#title ⇒ Object
Returns the value of attribute title.
4 5 6 |
# File 'lib/exhibitionist/shows.rb', line 4 def title @title end |
Class Method Details
.all ⇒ Object
9 10 11 |
# File 'lib/exhibitionist/shows.rb', line 9 def self.all @@all_shows end |
.brooklyn_scraper ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/exhibitionist/shows.rb', line 105 def self.brooklyn_scraper brooklyn_shows = [] html = open("https://www.brooklynmuseum.org/exhibitions") current_shows_page = Nokogiri::HTML(html) current_shows = current_shows_page.css("div.exhibitions").xpath("//h1[1]/following-sibling::div").css("div.image-card h2") current_shows.each do |show| begin new_show = self.new brooklyn_shows << new_show self.all << new_show new_show.title = show.text new_show.museum = Exhibitionist::Museums.find_or_create("Brooklyn Museum") new_show.dates = show.parent.css("h4") closing_date_object = Date.parse(new_show.dates.text.strip.gsub(/^.+\โ/, "")) new_show.closing_date = closing_date_object.strftime("%B %-d, %Y") new_show.days_left = (closing_date_object - Date.today).to_i if new_show.days_left < 0 self.all.delete(new_show) end rescue self.all.delete(new_show) end end brooklyn_shows end |
.met_scraper ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/exhibitionist/shows.rb', line 13 def self.met_scraper met_shows = [] html = open("http://www.metmuseum.org/press/exhibitions/2016/current-major-exhibitions") current_shows_page = Nokogiri::HTML(html) current_shows = current_shows_page.css("div.general-content p strong em a") current_shows.each do |show| begin new_show = self.new met_shows << new_show self.all << new_show new_show.title = show.text new_show.museum = Exhibitionist::Museums.find_or_create("Metropolitan Museum of Art") new_show.dates = show.parent.parent.next.next closing_date_object = Date.parse(new_show.dates.text.gsub(/^\n.+\โ/, "")) new_show.closing_date = closing_date_object.strftime("%B %-d, %Y") today = Date.today new_show.days_left = (closing_date_object - today).to_i if new_show.days_left < 0 self.all.delete(new_show) end rescue self.all.delete(new_show) end end met_shows end |
.moma_scraper ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/exhibitionist/shows.rb', line 42 def self.moma_scraper moma_shows = [] html = open("http://www.moma.org/calendar/exhibitions") current_shows_page = Nokogiri::HTML(html) current_shows = current_shows_page.css("ul.calendar-tile-list__section--featured li.calendar-tile") current_shows.each do |show| begin new_show = self.new moma_shows << new_show self.all << new_show new_show.title = show.css("h3").text.strip new_show.museum = Exhibitionist::Museums.find_or_create("MoMA") if show.css("p").text.strip.downcase != "ongoing" closing_date_object = Date.parse(show.css("p").text.gsub(/^(.+?),\s/, "").strip) new_show.closing_date = closing_date_object.strftime("%B %-d, %Y") new_show.days_left = (closing_date_object - Date.today).to_i else new_show.closing_date = "Ongoing" new_show.days_left = 9999 end if new_show.days_left < 0 self.all.delete(new_show) end rescue self.all.delete(new_show) end end moma_shows end |
.new_museum_scraper ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/exhibitionist/shows.rb', line 137 def self.new_museum_scraper new_museum_shows = [] html = open("http://www.newmuseum.org/exhibitions") current_shows_page = Nokogiri::HTML(html) current_shows = current_shows_page.css("div.columns div.exh a") current_shows.each do |show| begin new_show = self.new new_museum_shows << new_show self.all << new_show new_show.title = show.css("span.title").text new_show.museum = Exhibitionist::Museums.find_or_create("New Museum") new_show.dates = show.css("span.date-range") closing_date_object = Date.strptime("#{new_show.dates.text.gsub("Ending Soon", "").strip.gsub(/^.+\-/, "")}", "%m/%d/%y") new_show.closing_date = closing_date_object.strftime("%B %-d, %Y") new_show.days_left = (closing_date_object - Date.today).to_i if new_show.days_left < 0 self.all.delete(new_show) end rescue self.all.delete(new_show) end end new_museum_shows end |
.scrape_all ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/exhibitionist/shows.rb', line 207 def self.scrape_all begin self.met_scraper rescue self.all.delete_if { |show| show.museum.name == "Metropolitan Museum of Art"} puts "There was a problem scraping the Met's website. Finding other shows... \n\n" end begin self.moma_scraper rescue self.all.delete_if { |show| show.museum.name == "MoMA"} puts "There was a problem scraping the MoMA's website... \n\n" end begin self.whitney_scraper rescue self.all.delete_if { |show| show.museum.name == "Whitney"} puts "There was a problem scraping the Whitney's website... \n\n" end begin self.brooklyn_scraper rescue self.all.delete_if { |show| show.museum.name == "Brooklyn Museum"} puts "There was a problem scraping the Brooklyn Museum's website... \n\n" end begin self.new_museum_scraper rescue self.all.delete_if { |show| show.museum.name == "New Museum"} puts "There was a problem scraping the New Museum's website... \n\n" end end |
.sort_by_closing_date ⇒ Object
168 169 170 |
# File 'lib/exhibitionist/shows.rb', line 168 def self.sort_by_closing_date self.all.sort_by { |show| show.days_left } end |
.whitney_scraper ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/exhibitionist/shows.rb', line 74 def self.whitney_scraper whitney_shows = [] html = open("http://whitney.org/Exhibitions") current_shows_page = Nokogiri::HTML(html) current_shows = current_shows_page.css("div.exhibitions div.image") current_shows.each do |show| begin new_show = self.new whitney_shows << new_show self.all << new_show new_show.title = show.css("h3 a")[0].text.gsub("รข", "'").strip new_show.museum = Exhibitionist::Museums.find_or_create("Whitney") new_show.dates = show.css("h3 span") closing_date_object = Date.parse(new_show.dates.text.gsub(/^.+\โ/, "")) new_show.closing_date = closing_date_object.strftime("%B %-d, %Y") new_show.days_left = (closing_date_object - Date.today).to_i if new_show.days_left < 0 self.all.delete(new_show) end rescue self.all.delete(new_show) end end whitney_shows end |
Instance Method Details
#closing_info ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/exhibitionist/shows.rb', line 182 def closing_info if self.days_left == 0 puts "Hurry up! This show closes today!!" elsif self.days_left == 1 puts "Hurry Up! This show closes tomorrow!!" elsif self.days_left < 8 puts "Hurry up! This show closes in #{self.days_left} days!! It closes on #{self.closing_date}." elsif self.closing_date == "Ongoing" puts "This show is ongoing. You've got plenty of time." else puts "This show closes in #{self.days_left} days, on #{self.closing_date}." end end |
#closing_soon_alert ⇒ Object
173 174 175 176 177 178 179 |
# File 'lib/exhibitionist/shows.rb', line 173 def closing_soon_alert if self.days_left < 8 puts "CLOSING SOON!!! Hurry up, there are only" else end end |
#on_view_through ⇒ Object
198 199 200 201 202 203 204 205 |
# File 'lib/exhibitionist/shows.rb', line 198 def on_view_through if self.closing_date == "Ongoing" puts "This show is ongoing.\n\n" else puts "On view through #{self.closing_date}.\n\n" end end |