Skip to content

Instantly share code, notes, and snippets.

@FennyFatal
Created November 12, 2014 21:12
Show Gist options
  • Save FennyFatal/86fb11a065da62eabdbb to your computer and use it in GitHub Desktop.
Save FennyFatal/86fb11a065da62eabdbb to your computer and use it in GitHub Desktop.
require 'net/http'
require 'uri'
require 'win32/sound'
require 'launchy'
require 'thread'
include Win32
urls = [
"https://play.google.com/store/devices/details/Nexus_6_64GB_Midnight_Blue?id=nexus_6_blue_64gb",
"https://play.google.com/store/devices/details/Nexus_6_64GB_Cloud_White?id=nexus_6_white_64gb",
"https://play.google.com/store/devices/details/Nexus_6_32GB_Cloud_White?id=nexus_6_white_32gb",
"https://play.google.com/store/devices/details/Nexus_6_32GB_Midnight_Blue?id=nexus_6_blue_32gb"
]
def open(uri)
Net::HTTP.post_form(uri, 'ipf' => '1','xhr' => '1').body
end
def beep
Sound.beep(600, 100)
Sound.beep(600, 100)
Sound.beep(600, 100)
Sound.beep(600, 100)
end
def checkForAvailability(url)
last_time = 0
uri = URI.parse(url)
while true
content = open(uri)
if content.include? 'Leaves warehouse by'
if (Time.now.to_f - last_time) > 30
Launchy.open url
last_time = Time.now.to_f
end
puts "#{Time.now.strftime("%d/%m/%Y %H:%M:%S")}: Available #{uri.query}"
Thread.new{beep}
else
puts "#{Time.now.strftime("%d/%m/%Y %H:%M:%S")}: Not available #{uri.query}"
end
end
end
threads = [Thread.new{beep}]
urls.each do |url|
puts url
threads << Thread.new{checkForAvailability(url)}
end
threads.each do |thread|
thread.join
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment