@@ -245,15 +245,22 @@ namespace :menu_import do
245
245
246
246
# Pomona's system is batshit crazy (user inputted text in Google Docs),
247
247
# so we're just going to scrape from their website instead
248
- browser = Watir ::Browser . new :chrome , headless : true
248
+ browser = Watir ::Browser . new :chrome , headless : true , :args => [ "--no-sandbox" ]
249
249
browser . goto 'www.pomona.edu/administration/dining/menus/frary'
250
250
251
- menu = browser . div ( :class => 'pom-accordion' )
251
+ # The website was updated during COVID, so the structure is slightly different
252
+ # e.g. no need to click this button
253
+ # browser.button(class: 'accordion__header').click
254
+
255
+ menu = browser . div ( class : [ 'accordion' , 'js-accordion' ] )
256
+ # menu.each do |e|
257
+ # menu = e
258
+ # end
252
259
meal_type = ''
253
260
station = ''
254
261
meal_menu = Menu
255
262
256
- menu_panels = menu . h3s ( :class => 'ui-accordion-header ' )
263
+ menu_panels = menu . buttons ( :class => 'accordion__header ' )
257
264
panel_count = 1 # the next panel to open
258
265
259
266
# Map the successive divs to be pairs of {day, menu}
@@ -265,7 +272,7 @@ namespace :menu_import do
265
272
# meal type (h2)
266
273
# station (h3)
267
274
# menu items (div)
268
- pair [ :menu ] . children . each do |div |
275
+ pair [ :menu ] . div . children . each do |div |
269
276
if div . tag_name == "h2"
270
277
meal_type = div . text . downcase
271
278
if ( pair [ :day ] == 'saturday' || pair [ :day ] == 'sunday' ) && meal_type == 'breakfast'
@@ -282,12 +289,12 @@ namespace :menu_import do
282
289
)
283
290
elsif div . tag_name == "div" && div . class_name == "nutrition-menu-section"
284
291
div . children . each do |menu_item |
285
- MenuItem . create ( :name => menu_item . p . text , :station => station , :menu => meal_menu )
292
+ MenuItem . find_or_create_by ( :name => menu_item . p . text , :station => station , :menu => meal_menu )
286
293
end
287
294
end
288
295
end
289
296
# simulate click to open the next panel after parsing the current one
290
- menu_panels [ panel_count ] . fire_event ( 'click' ) unless panel_count > 6
297
+ menu_panels [ panel_count ] . fire_event ( 'click' ) unless panel_count >= menu_panels . length
291
298
panel_count += 1
292
299
end
293
300
@@ -306,15 +313,19 @@ namespace :menu_import do
306
313
307
314
# Pomona's system is batshit crazy (user inputted text in Google Docs),
308
315
# so we're just going to scrape from their website instead
309
- browser = Watir ::Browser . new :chrome , headless : true
316
+ browser = Watir ::Browser . new :chrome , headless : true , :args => [ "--no-sandbox" ]
310
317
browser . goto 'www.pomona.edu/administration/dining/menus/frank'
311
318
312
- menu = browser . div ( :class => 'pom-accordion' )
319
+ # The website was updated during COVID, so the structure is slightly different
320
+ # e.g. class names have been slightly changed
321
+ # e.g. Frank is now open on Fridays sometimes
322
+
323
+ menu = browser . div ( class : [ 'accordion' , 'js-accordion' ] )
313
324
meal_type = ''
314
325
station = ''
315
326
meal_menu = Menu
316
327
317
- menu_panels = menu . h3s ( :class => 'ui-accordion-header ' )
328
+ menu_panels = menu . buttons ( :class => 'accordion__header ' )
318
329
panel_count = 1 # the next panel to open
319
330
320
331
# Map the successive divs to be pairs of {day, menu}
@@ -326,31 +337,33 @@ namespace :menu_import do
326
337
# meal type (h2)
327
338
# station (h3)
328
339
# menu items (div)
329
- unless pair [ :day ] == 'friday' || pair [ :day ] == 'saturday'
330
- pair [ :menu ] . children . each do |div |
331
- if div . tag_name == "h2"
332
- meal_type = div . text . downcase
333
- if pair [ :day ] == 'sunday' && meal_type == 'breakfast'
334
- meal_type = 'brunch'
335
- end
336
- elsif div . tag_name == "h3"
337
- station = div . text
338
- hours = _get_pomona_hours ( 'Frank' , Date . strptime ( pair [ :day ] , '%A' ) . wday , meal_type )
339
- meal_menu = Menu . find_or_create_by (
340
- :day => pair [ :day ] ,
341
- :dining_hall => :frank ,
342
- :meal_type => meal_type ,
343
- :hours => hours
344
- )
345
- elsif div . tag_name == "div" && div . class_name == "nutrition-menu-section"
346
- div . children . each do |menu_item |
347
- MenuItem . create ( :name => menu_item . p . text , :station => station , :menu => meal_menu )
348
- end
340
+ pair [ :menu ] . div . children . each do |div |
341
+ if div . tag_name == "p"
342
+ # <p> is used to denote that Frank is closed that day
343
+ next
344
+ end
345
+ if div . tag_name == "h2"
346
+ meal_type = div . text . downcase
347
+ if pair [ :day ] == 'sunday' && meal_type == 'breakfast'
348
+ meal_type = 'brunch'
349
+ end
350
+ elsif div . tag_name == "h3"
351
+ station = div . text
352
+ hours = _get_pomona_hours ( 'Frank' , Date . strptime ( pair [ :day ] , '%A' ) . wday , meal_type )
353
+ meal_menu = Menu . find_or_create_by (
354
+ :day => pair [ :day ] ,
355
+ :dining_hall => :frank ,
356
+ :meal_type => meal_type ,
357
+ :hours => hours
358
+ )
359
+ elsif div . tag_name == "div" && div . class_name == "nutrition-menu-section"
360
+ div . children . each do |menu_item |
361
+ MenuItem . find_or_create_by ( :name => menu_item . p . text , :station => station , :menu => meal_menu )
349
362
end
350
363
end
351
364
end
352
365
# simulate click to open the next panel after parsing the current one
353
- menu_panels [ panel_count ] . fire_event ( 'click' ) unless panel_count > 6
366
+ menu_panels [ panel_count ] . fire_event ( 'click' ) unless panel_count >= menu_panels . length
354
367
panel_count += 1
355
368
end
356
369
@@ -369,7 +382,7 @@ namespace :menu_import do
369
382
370
383
# Pomona's system is batshit crazy (user inputted text in Google Docs),
371
384
# so we're just going to scrape from their website instead
372
- browser = Watir ::Browser . new :chrome , headless : true
385
+ browser = Watir ::Browser . new :chrome , headless : true , :args => [ "--no-sandbox" ]
373
386
browser . goto 'www.pomona.edu/administration/dining/menus/oldenborg'
374
387
375
388
menu = browser . div ( :class => 'pom-accordion' )
@@ -494,4 +507,4 @@ namespace :menu_import do
494
507
end
495
508
end
496
509
end
497
- end
510
+ end
0 commit comments