Created
July 5, 2017 09:14
-
-
Save chsh/a577f08ff6fd9af97288a772fbbbf843 to your computer and use it in GitHub Desktop.
Nintendo Switch stock checker for my nintendo store. ;-)
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 'bundler' | |
Bundler.require | |
def info(msg) | |
File.open('activity.log', 'a+') do |f| | |
f.puts "#{Time.now.strftime('%Y-%m-%d %H:%M:%S')} I: #{msg}" | |
end | |
end | |
def warn(msg) | |
File.open('activity.log', 'a+') do |f| | |
f.puts "#{Time.now.strftime('%Y-%m-%d %H:%M:%S')} W: #{msg}" | |
end | |
end | |
begin | |
notifier = Slack::Notifier.new 'SET-YOUR_SLACK-WEBHOOK-URL' | |
url = 'https://store.nintendo.co.jp/customize.html' | |
content = open(url).read | |
if content =~ /\bSOLD\s+OUT\b/ | |
info('Nintendo Switch SOLD OUT.') | |
else | |
notifier.ping "Hi, @chsh. My Nintendo Store customization html has been changed.<#{url}>" | |
end | |
rescue SocketError | |
warn("Network error. No internet connection.") | |
end |
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
#!/bin/zsh | |
# Customize to your needs... | |
export PATH="$HOME/.rbenv/shims:$HOME/Scripts:/usr/local/bin:$PATH" | |
eval "$(~/.rbenv/bin/rbenv init -)" | |
cd ~/Sources/nintendo-switch/ | |
bundle exec ruby check.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
*/5 8-20 * * * ~/Sources/nintendo-switch/check.sh > /dev/null |
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
source 'https://rubygems.org' | |
gem 'slack-notifier' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment