Initial commit.
Not yet sure if VCR is working right to stub tests, I expect it isn't. We do have basic scraping ability though.
This commit is contained in:
commit
c08a880b51
1179
14Aug2019-Lunch.yml
Normal file
1179
14Aug2019-Lunch.yml
Normal file
File diff suppressed because one or more lines are too long
8
Gemfile
Normal file
8
Gemfile
Normal file
|
@ -0,0 +1,8 @@
|
|||
source 'https://rubygems.org'
|
||||
|
||||
gem 'watir'
|
||||
gem 'nokogiri'
|
||||
gem 'webdrivers'
|
||||
gem 'minitest'
|
||||
gem 'webmock'
|
||||
gem 'vcr'
|
48
Gemfile.lock
Normal file
48
Gemfile.lock
Normal file
|
@ -0,0 +1,48 @@
|
|||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
addressable (2.6.0)
|
||||
public_suffix (>= 2.0.2, < 4.0)
|
||||
childprocess (1.0.1)
|
||||
rake (< 13.0)
|
||||
crack (0.4.3)
|
||||
safe_yaml (~> 1.0.0)
|
||||
hashdiff (1.0.0)
|
||||
mini_portile2 (2.4.0)
|
||||
minitest (5.11.3)
|
||||
nokogiri (1.10.4)
|
||||
mini_portile2 (~> 2.4.0)
|
||||
public_suffix (3.1.1)
|
||||
rake (12.3.3)
|
||||
regexp_parser (1.6.0)
|
||||
rubyzip (1.2.3)
|
||||
safe_yaml (1.0.5)
|
||||
selenium-webdriver (3.142.3)
|
||||
childprocess (>= 0.5, < 2.0)
|
||||
rubyzip (~> 1.2, >= 1.2.2)
|
||||
vcr (5.0.0)
|
||||
watir (6.16.5)
|
||||
regexp_parser (~> 1.2)
|
||||
selenium-webdriver (~> 3.6)
|
||||
webdrivers (4.1.2)
|
||||
nokogiri (~> 1.6)
|
||||
rubyzip (~> 1.0)
|
||||
selenium-webdriver (>= 3.0, < 4.0)
|
||||
webmock (3.6.2)
|
||||
addressable (>= 2.3.6)
|
||||
crack (>= 0.3.2)
|
||||
hashdiff (>= 0.4.0, < 2.0.0)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
minitest
|
||||
nokogiri
|
||||
vcr
|
||||
watir
|
||||
webdrivers
|
||||
webmock
|
||||
|
||||
BUNDLED WITH
|
||||
2.0.2
|
9
README.md
Normal file
9
README.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
# Lunch Announcements
|
||||
|
||||
A very specific utility for scraping my eldest son's elementary school lunch menu site and texting us what he's having for lunch that day.
|
||||
|
||||
## Requirements
|
||||
|
||||
* Ruby
|
||||
* Nokogiri / Watir
|
||||
* [chrome webdriver](https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver)
|
10
Rakefile
Normal file
10
Rakefile
Normal file
|
@ -0,0 +1,10 @@
|
|||
require 'rake/testtask'
|
||||
|
||||
Rake::TestTask.new do |t|
|
||||
t.libs << 'test'
|
||||
t.libs << 'lib'
|
||||
t.test_files = FileList['test/**/*_test.rb']
|
||||
end
|
||||
desc 'Run tests'
|
||||
|
||||
task default: :test
|
23
lib/lunch_scraper.rb
Normal file
23
lib/lunch_scraper.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
require 'watir'
|
||||
require 'nokogiri'
|
||||
|
||||
class LunchScraper
|
||||
def initialize(date)
|
||||
@date = date
|
||||
@url = "https://westerville.nutrislice.com/menu/fouse-elementary/lunch/#{@date.strftime('%Y-%m-%d')}"
|
||||
end
|
||||
|
||||
def today
|
||||
browser = Watir::Browser.new :chrome, headless: true
|
||||
browser.goto @url
|
||||
# browser.wait_until { |b| b.h3(class: ['day-label', 'today']).present? }
|
||||
browser.wait_until { |b| b.button(text: 'View Menus').present? }
|
||||
browser.button(text: 'View Menus').click
|
||||
|
||||
browser.p(class: 'no-data').wait_while(&:exists?)
|
||||
browser.wait_until { |b| b.h3(class: ['day-label', 'today']).present? }
|
||||
|
||||
page = Nokogiri::HTML(browser.html)
|
||||
page.css('h3.day-label.today ~ ul.items li a.food-name-inner').map(&:content)
|
||||
end
|
||||
end
|
196
test/cassettes/14Aug2019-Lunch.yml
Normal file
196
test/cassettes/14Aug2019-Lunch.yml
Normal file
File diff suppressed because one or more lines are too long
22
test/lib/lunch_scraper_test.rb
Normal file
22
test/lib/lunch_scraper_test.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
require 'minitest/autorun'
|
||||
require 'webdrivers/chromedriver'
|
||||
require 'vcr'
|
||||
require_relative '../../lib/lunch_scraper'
|
||||
|
||||
VCR.configure do |config|
|
||||
config.cassette_library_dir = "test/cassettes/"
|
||||
config.ignore_hosts('127.0.0.1')
|
||||
config.ignore_hosts(*(ObjectSpace.each_object(Webdrivers::Common.singleton_class).to_a - [Webdrivers::Common]).map { |driver| URI(driver.base_url).host })
|
||||
config.hook_into :webmock
|
||||
end
|
||||
|
||||
class LunchScraperTest < MiniTest::Spec
|
||||
describe "Getting today's lunch" do
|
||||
it 'can parse out the correct lunch items' do
|
||||
VCR.use_cassette('14Aug2019-Lunch') do
|
||||
@lunch = LunchScraper.new(Date.today)
|
||||
puts @lunch.today.inspect
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue