Skip to content

Instantly share code, notes, and snippets.

@cvd
Created November 30, 2016 01:57
Show Gist options
  • Save cvd/a75ebaf0d00b3eeeecdbed6fe279eee1 to your computer and use it in GitHub Desktop.
Save cvd/a75ebaf0d00b3eeeecdbed6fe279eee1 to your computer and use it in GitHub Desktop.
Get the tots

Setup

Requires ruby... if you're on a mac you're good

sudo gem install nokogiri (remove sudo if you know you don't need that)

run with ruby tots.rb

require 'nokogiri'
require 'open-uri'
def get_day(item_node)
item_node.parent.parent.parent.parent.parent.attributes['id'].value
end
def tot_days(nodes)
nodes.map {|node| get_day(node) }
end
menu_url = 'http://shopmason.gmu.edu/WeeklyMenu/SouthsideMenu/index.html'
html = open(menu_url)
# uncomment if you save the html to a local file called 'tots.html' for local testing
# save the file like so: `curl http://shopmason.gmu.edu/WeeklyMenu/SouthsideMenu/index.html > tots.html`
# html = File.read('tots.html')
doc = Nokogiri::HTML(html)
tot_names = ["French Fried Tater Tots", "Loaded Cheese Tots"]
tot_nodes = doc.css('div.menuitem span').select do |node|
tot_names.member? node.content
end
mmmmm = tot_days(tot_nodes)
if mmmmm.length > 0
puts "TOTS ON:"
puts mmmmm
puts "HOLY SHIT! EAT TOTS, GET MONEY. https://tots.io (TM, patent pending)"
else
puts "NO TOTS!"
puts "QUIT SCHOOL"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment