Last active
August 29, 2015 14:14
-
-
Save uebo/9c0b6eb191d1552b3d7b to your computer and use it in GitHub Desktop.
get_nexus6.rb
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
require 'open-uri' | |
require 'nokogiri' | |
require 'mail' | |
# メールのFrom, toを設定 | |
mail = Mail.new do | |
from '[email protected]' | |
to '[email protected]' | |
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 => '[email protected]', | |
: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