Skip to content

Instantly share code, notes, and snippets.

@rb2k
Last active August 29, 2015 14:06
Show Gist options
  • Save rb2k/5f8a881a698ff20ba2ba to your computer and use it in GitHub Desktop.
Save rb2k/5f8a881a698ff20ba2ba to your computer and use it in GitHub Desktop.
apple iphone 6 search
require 'json'
require 'open-uri'
phones = {
'64 gb silver tmo' => 'MG5C2LL%2FA',
'64 gb gray tmo' => 'MG5A2LL%2FA'
}
zip_code = '02138'
loop do
system('clear')
phones.each_pair do |phone_type, code|
data = open("http://store.apple.com/us/retailStore/availabilitySearch?parts.0=#{code}&zip=#{zip_code}").read
JSON.parse(data)['body']['stores'].each do |store|
store['partsAvailability'].each do |item, availability|
available = !availability['pickupQuote'].include?('unavailable')
puts "****************" if available
puts "#{phone_type}: #{availability['pickupQuote']}"
puts "****************" if available
if available
system("say 'found an iphone'")
exit
end
end
end
end
puts "#{Time.now} ---------------------------"
sleep 600
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment