Last active
August 29, 2015 14:06
-
-
Save ericmaxwell2003/8861e7ffd79912a7619f to your computer and use it in GitHub Desktop.
Groovy Script to determine if there are any 64 or 128 byte iPhone 6 Plus's in Columbus Ohio. (specifically at the Easton or Polaris stores).
This file contains 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
/** | |
* Simple script you can run in GroovyConsole or elsewhere to quickly find 64 or 128 byte | |
* iPhone 6 plus's in Columbus. | |
* | |
* You could easily adapt this to work for other locations as well.. It's pretty amazing | |
* how much infomration you can get back from Apple and how easy it is to get it. | |
* | |
* The link to get the JSON describing whether the phone is in and details for stores, ordered from | |
* closest to farthest by zip code is: | |
* "http://store.apple.com/us/retailStore/availabilitySearch?parts.0=${partNumber}&zip=${zip}", | |
* | |
* Results similar to this : http://store.apple.com/us/retailStore/availabilitySearch?parts.0=MG4X2LL%2FA&zip=43064 | |
* If it's found, the element storeSelectionEnabled will be set to true. Other information such as store | |
* hours and phone numbers is there too.. | |
* | |
*/ | |
String zip = 43064 | |
int polaris = 0 | |
int easton = 1 | |
def isAtStore = { Map jsonResult, int store -> | |
return jsonResult.body.stores[store].partsAvailability.values()[0].storeSelectionEnabled.toBoolean() | |
} | |
Map phones = [ | |
'iPhone 6 64GB Silver (GSM) AT&T':"http://store.apple.com/us/retailStore/availabilitySearch?parts.0=MG4X2LL%2FA&zip=${zip}", | |
'iPhone 6 Plus 64GB Silver (GSM) AT&T': "http://store.apple.com/us/retailStore/availabilitySearch?parts.0=MGAV2LL%2FA&zip=${zip}", | |
'iPhone 6 Plus 128GB Silver (GSM) AT&T' : "http://store.apple.com/us/retailStore/availabilitySearch?parts.0=MGAQ2LL%2FA&zip=${zip}", | |
'Phone 6 Plus 64GB Gold (GSM) AT&T': "http://store.apple.com/us/retailStore/availabilitySearch?parts.0=MGAW2LL%2FA&zip=${zip}", | |
'iPhone 6 Plus 128GB Gold (GSM) AT&T': "http://store.apple.com/us/retailStore/availabilitySearch?parts.0=MGAR2LL%2FA&zip=${zip}", | |
] | |
phones.each { model, searchUrl -> | |
String rawJsonStr = new URL(searchUrl).getText() | |
def slurper = new groovy.json.JsonSlurper() | |
def result = slurper.parseText(rawJsonStr) | |
String isAtPolaris = isAtStore(result, polaris) ? 'Yes':'No' | |
String isAtEaston = isAtStore(result, easton) ? 'Yes':'No' | |
println "${isAtPolaris} - at Polaris - ${model}" | |
println "${isAtEaston} - at Easton - ${model}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment