Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@uebo
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uebo/9c0b6eb191d1552b3d7b to your computer and use it in GitHub Desktop.
Save uebo/9c0b6eb191d1552b3d7b to your computer and use it in GitHub Desktop.
get_nexus6.rb
require 'open-uri'
require 'nokogiri'
require 'mail'
# メールのFrom, toを設定
mail = Mail.new do
from 'xxxx@gmail.com'
to 'xxxx@gmail.com'
end
# あまりよろしくないみたいですが、SSL通信でエラーが出るのを回避するための設定
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
# gmailのsmtpを利用します
mail_options = { :address => "smtp.gmail.com",
:port => 587,
:domain => "smtp.gmail.com",
:user_name => 'xxxx@gmail.com',
:password => 'password',
:authentication => :plain,
:enable_starttls_auto => true }
# nexus6のGoogle Playサイト
urls = {
"Nexus6 32GB White" => "https://play.google.com/store/devices/details?id=nexus_6_blue_32gb&hl=ja",
"Nexus6 32GB DarkBlue" => "https://play.google.com/store/devices/details/?id=nexus_6_white_32gb&hl=ja",
"Nexus6 64GB White" => "https://play.google.com/store/devices/details?id=nexus_6_blue_64gb&hl=ja",
"Nexus6 64GB DarkBlue" => "https://play.google.com/store/devices/details?id=nexus_6_white_64gb&hl=ja",
}
charset = nil
urls.each do |name, url|
# HTMLを読み込み、nokogiriを使ってdocオブジェクトを作成します
html = open(url) do |f|
charset = f.charset
f.read
end
doc = Nokogiri::HTML.parse(html, nil, charset)
# 在庫状態部分のHTMLを監視します
doc.xpath('//div[@class="shipping-status-align"]').each do |node|
# p node.inner_text
if node.inner_text != " 現在在庫切れです。しばらくしてからもう一度ご確認ください。 "
mail.subject = name + " ステータス変わりました!"
mail.body = name + "\n" + url
mail.delivery_method(:smtp, mail_options)
mail.deliver
end
end
# あまり迷惑を掛けない程度に・・・
sleep(1)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment