Skip to content

Instantly share code, notes, and snippets.

@founddrama
Created January 18, 2016 01:56
Show Gist options
  • Save founddrama/8c2b7b5bec711ecb85d9 to your computer and use it in GitHub Desktop.
Save founddrama/8c2b7b5bec711ecb85d9 to your computer and use it in GitHub Desktop.
Screenscraper in miniature to look up the menu on the school website and mail it to me.
require 'net/http'
require 'nokogiri'
require 'net/smtp'
require 'securerandom'
page = Nokogiri::HTML(Net::HTTP.get(:DOMAIN_REDACTED, '/food-service/'))
days = page.css('.lunch-calendar thead th').collect { |td| td.text }
menu = page.css('.lunch-calendar tbody tr:first-of-type td a').collect { |td| td.text }
combined = days.zip(menu).collect { |tuple| tuple.join ': ' }
now = Time.new
message_string = <<END_OF_MESSAGE
From: #{:NAME_REDACTED} Menu <#{:EMAIL_REDACTED}>
To: #{:NAME_REDACTED} <#{:EMAIL_REDACTED}>
Subject: #{:NAME_REDACTED} Menu for Week of #{now.mon}/#{now.day}
Date: #{now.strftime('%a, %d %b %Y %T %z')}
Message-Id: <#{SecureRandom.uuid}@#{:DOMAIN_REDACTED}>
The #{:NAME_REDACTED} Menu for the week of #{now.mon}/#{now.day}:
#{combined.join "\n"}
END_OF_MESSAGE
smtp = Net::SMTP.new(:DOMAIN_REDACTED, 587)
smtp.start(:DOMAIN_REDACTED, :USER_REDACTED, :PASS_REDACTED, :login) do |smtp|
smtp.send_message message_string, :EMAIL_REDACTED, :EMAIL_REDACTED
smtp.finish
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment