Last active
October 27, 2017 05:27
-
-
Save kawakubox/d0ce5b18f2bec2c02b32fba0709ed4dd to your computer and use it in GitHub Desktop.
Nintendo Switch の在庫確認する bitbar plug-in
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 /Users/kawakubox/.rbenv/shims/ruby | |
# 以下の 2gem を install していることが前提 | |
# $ gem install 'faraday' | |
# $ gem install 'oga' | |
require 'faraday' | |
require 'oga' | |
watchlist = [ | |
{ | |
name: 'ヨドバシ.com(Switch 赤青)', | |
url: 'http://www.yodobashi.com/%E4%BB%BB%E5%A4%A9%E5%A0%82-Nintendo-Nintendo-Switch-Joy-Con-L-%E3%83%8D%E3%82%AA%E3%83%B3%E3%83%96%E3%83%AB%E3%83%BC-R-%E3%83%8D%E3%82%AA%E3%83%B3%E3%83%AC%E3%83%83%E3%83%89-Nintendo-Switch%E6%9C%AC%E4%BD%93/pd/100000001003431566/', | |
selector: '#js_buyBoxMain .buyBtn', | |
}, | |
{ | |
name: 'ヨドバシ.com(Switch グレー)', | |
url: 'http://www.yodobashi.com/%E4%BB%BB%E5%A4%A9%E5%A0%82-Nintendo-Nintendo-Switch-Joy-Con-L-R-%E3%82%B0%E3%83%AC%E3%83%BC-Nintendo-Switch%E6%9C%AC%E4%BD%93/pd/100000001003431565/', | |
selector: '#js_buyBoxMain .buyBtn', | |
}, | |
{ | |
name: 'ヨドバシ.com(Switch Splatoon2 モデル)', | |
url: 'http://www.yodobashi.com/product/100000001003570628/', | |
selector: '#js_buyBoxMain .buyBtn', | |
}, | |
{ | |
name: 'ヨドバシ.com(マリオ モデル)', | |
url: 'http://www.yodobashi.com/product/100000001003690561/', | |
selector: '#js_buyBoxMain .buyBtn', | |
}, | |
] | |
results = watchlist.map do |item| | |
doc = Oga.parse_html(Faraday.get(item[:url]).body.force_encoding('UTF-8')) | |
item if doc.at_css(item[:selector]) | |
end.compact | |
if results.empty? | |
puts '在庫なし' | |
else | |
puts '在庫あり | color=red' | |
end | |
puts '---' | |
results.each { |item| puts "#{item[:name]} | bash=\"open #{item[:url]}\"" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
クリック時の terminal が残る、、、