Skip to content

Instantly share code, notes, and snippets.

@chsh
Created July 5, 2017 09:14
Show Gist options
  • Save chsh/a577f08ff6fd9af97288a772fbbbf843 to your computer and use it in GitHub Desktop.
Save chsh/a577f08ff6fd9af97288a772fbbbf843 to your computer and use it in GitHub Desktop.
Nintendo Switch stock checker for my nintendo store. ;-)
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
#!/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
*/5 8-20 * * * ~/Sources/nintendo-switch/check.sh > /dev/null
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