Skip to content

Instantly share code, notes, and snippets.

@bdashrad
Created April 16, 2016 05:51
Show Gist options
  • Save bdashrad/c66d3c02a05f86d8a17c5e7888593b86 to your computer and use it in GitHub Desktop.
Save bdashrad/c66d3c02a05f86d8a17c5e7888593b86 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'json'
require 'open-uri'
phones = {
'64 gb silver att' => 'MG4X2LL%2FA',
'64 gb gray att' => 'MG4W2LL%2FA',
'64 gb gold att' => 'MG502LL%2FA'
}
zip_code = '01826'
phone_number = '9788220077'
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}&ts=#{Time.now.to_i}").read
JSON.parse(data)['body']['stores'].each_with_index do |store, index|
next if index > 10
store['partsAvailability'].each do |item, availability|
available = !availability['pickupQuote'].include?('unavailable')
puts "****************" if available
puts "#{phone_type.ljust(20)}:\t#{store['storeDisplayName'].gsub('Apple Store, ', '').ljust(25)}\t#{availability['pickupQuote'].rjust(50)}"
puts "****************" if available
if available
system("say 'found an iphone'")
system("curl http://textbelt.com/text -d number=#{phone_number} -d 'message=#{phone_type} #{store['storeDisplayName'].gsub('Apple Store, ', '')}'")
sleep 300
#exit
end
end
end
end
puts "#{Time.now} ---------------------------"
sleep 60
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment