Created
November 19, 2013 23:38
-
-
Save arthuralee/7554580 to your computer and use it in GitHub Desktop.
Queries the Apple Store servers to check for black iPhone 5ses in my zip code. Also sends a push notification via a Parse app
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
var request = require("request"); | |
var models = { | |
"16 GB": "ME341LL%2FA", | |
"32 GB": "ME344LL%2FA", | |
"64 GB": "ME347LL%2FA" | |
}; | |
var result = function(size) { | |
return function (error, response, body) { | |
if (!error && response.statusCode == 200) { | |
var obj = body["body"]["stores"][0]["partsAvailability"]; | |
for (var foo in obj) {break} | |
var status = obj[foo]["pickupDisplay"]; | |
console.log(size, status); | |
if (status === "available") { | |
sendPush(size); | |
} else { | |
setTimeout(function() { | |
check(size); | |
}, 10000); | |
} | |
} | |
} | |
} | |
var check = function(size) { | |
var url = "http://store.apple.com/us/retail/availabilitySearch?parts.0=" + models[size] + "&zip=15213"; | |
request({url:url,json:true}, result(size)); | |
} | |
var sendPush = function(size) { | |
request.post({ | |
url: "https://api.parse.com/1/push", | |
headers: { | |
"X-Parse-Application-Id": "5A9EfXnFioaOJqYYo04jDppzxZmn1aFUNJMC4xFx", | |
"X-Parse-REST-API-Key": "IwlUrMrHewtGRpAZb6kVNk0o4mCAJtb1I4fJvhLL" | |
}, | |
json : { | |
"where": { | |
"deviceType": "ios" | |
}, | |
"data": { | |
"sound" : "", | |
"alert" : "iPhone 5s [Space Grey] " + size + " now available @ Shadyside" | |
} | |
} | |
}); | |
} | |
for (var size in models) { | |
check(size); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment