require 'rubygems'
require 'mechanize'
require 'pony'
Pony.options = {
:from => 'you@you.com',
:via => :smtp,
:via_options => {
:address => 'your-mailhost.you.com',
:port => '587',
:enable_starttls_auto => true,
:user_name => 'mail-user-name',
:password => 'mail-password',
:authentication => :login,
:domain => "localhost.localdomain"
}
}
a = Mechanize.new
a.user_agent_alias = 'Mac Safari'
url = 'http://store.apple.com/go/uk/vieworder/APPLE_ORDER_NO/EMAIL_ADDRESS/'
status = 'Processing Items'
while status == 'Processing Items'
page = a.get(url) rescue nil
if page
status = page.search('.h3 .strong')[0].text
delivery = page.search('.h5 > .block')[0].text.strip.gsub(/\s+/, ' ')
puts "#{Time.now.strftime('%H:%M:%S')} - #{status} - #{delivery}"
else
puts "#{Time.now.strftime('%H:%M:%S')} - Unable to contact Apple Store"
end
sleep 300
end
Pony.mail(:to => 'you@you.com', subject: "Apple Store Order ", body: "Order status now: #{status}\n\n#{url}")