Created
February 8, 2011 19:28
-
-
Save breeno/817028 to your computer and use it in GitHub Desktop.
Cause, well, you wanna know RIGHT AWAY when this page changes....
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'digest/sha1' | |
require 'tlsmail' | |
require 'time' | |
# To use: | |
# gem install tlsmail | |
# edit below settings for your gmail account | |
# | |
USER_EMAIL = '[email protected]' | |
USER_NAME = 'changeme' | |
USER_PASSWORD = 'changeme' | |
# send email helper | |
def send_email(from, from_alias, to, to_alias, subject, message, username, password) | |
msg = <<END_OF_MESSAGE | |
From: #{from_alias} <#{from}> | |
To: #{to_alias} <#{to}> | |
Subject: #{subject} | |
#{message} | |
END_OF_MESSAGE | |
Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE) | |
Net::SMTP.start('smtp.gmail.com', 587, 'gmail.com', username, password, :login) do |smtp| | |
smtp.send_message(msg, from, to) | |
end | |
end | |
# check dub dub page | |
def check_wwdc_page_for_change | |
# get previous sha1 | |
previous_sha1 = '' | |
wwdc_last_sha1_file_name = File.expand_path("~/.wwdc_last_sha1.txt") | |
if File.exists?(wwdc_last_sha1_file_name) | |
sha1_file = File.open(wwdc_last_sha1_file_name, 'r') | |
previous_sha1 = sha1_file.read | |
sha1_file.close | |
end | |
# grab page and compute sha1 | |
wwdc_info_page = `curl http://developer.apple.com/wwdc/` | |
sha1 = Digest::SHA1.hexdigest(wwdc_info_page) | |
# report | |
if sha1 != previous_sha1 | |
puts "Site has changed!" | |
send_email( '[email protected]', 'WWDC cron', USER_EMAIL, USER_NAME, 'WWDC page has changed', 'Dude, http://developer.apple.com/wwdc/ has changed', USER_EMAIL, USER_PASSWORD) | |
else | |
puts "No update." | |
end | |
#save new sha1 | |
sha1_file = File.open(wwdc_last_sha1_file_name, 'w') | |
sha1_file.write(sha1) | |
sha1_file.close | |
end | |
check_wwdc_page_for_change |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment