Skip to content

Instantly share code, notes, and snippets.

@venj
Last active August 29, 2015 14:16
Show Gist options
  • Save venj/a2cdd2680d37ab286263 to your computer and use it in GitHub Desktop.
Save venj/a2cdd2680d37ab286263 to your computer and use it in GitHub Desktop.
A script to detect referb iPad mini 2 availablility in China.
#!/usr/bin/env ruby
# encoding = UTF-8
require "open-uri"
begin
require 'mailx' # Or main for *nix
rescue LoadError => e
STDERR.puts "Please install mail gem first."
exit 1
end
LINK = "http://store.apple.com/cn/browse/home/specialdeals/ipad/ipad_mini_2"
def detect
html = open(LINK).read
index = html.index("抱歉,没有可用的产品,请稍后再回来查看。")
if index and index > 0
puts "Mini 2 not availble."
else
puts "Mini 2 is available."
send_mail
end
end
def send_mail
options = { :address => "<smtp_server>",
:port => 25, # maybe other port for ssl.
:domain => '<mail_server_domain>',
:user_name => '<username>',
:password => '<password>',
:authentication => 'plain',
:enable_starttls_auto => true }
Mail.defaults do
delivery_method :smtp, options
end
Mail.deliver do
to '<receiver>'
from '<sender>'
subject 'iPad mini 2 referb available!'
body "iPad mini 2 referb available to buy.\n\n#{LINK}"
end
end
detect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment