Skip to content

Instantly share code, notes, and snippets.

@aamaliaa
Last active December 24, 2015 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aamaliaa/6794853 to your computer and use it in GitHub Desktop.
Save aamaliaa/6794853 to your computer and use it in GitHub Desktop.
CLI iPhone5s stock checker, inspired by https://medium.com/p/7f921ea94e8f run with node.js
var http = require('http');
var zip = process.argv[2] || '10018'; // defaults to 10018
var phone = process.argv[3] || 'ME349LL/A'; // defaults to 64GB Gold Verizon
var checkForPhones = function(zip, phone){
console.log('Checking for ' + phone + ' near ' + zip + '...');
console.log('=====================================');
var options = {
host: 'store.apple.com',
port: '80',
path: '/us/retail/availabilitySearch?parts.0=' + phone + '&zip=' + zip,
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
};
var req = http.request(options, function(res){
var output = '';
res.setEncoding('utf8');
res.on('data', function (chunk) {
output += chunk;
});
res.on('end', function() {
var obj = JSON.parse(output);
var stores = obj.body.stores;
for(var prop in stores){
var status = stores[prop]['partsAvailability'][phone]['pickupDisplay'],
store = stores[prop]['storeName'],
number = stores[prop]['phoneNumber'];
console.log(status === 'available' ?
status + ' @ ' + store + ' !!!! CALL NOW @ ' + number + ' !!!!':
status + ' @ ' + store
);
}
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
req.end();
}
checkForPhones(zip, phone);
@jhofman
Copy link

jhofman commented Oct 2, 2013

nice---i went for a python crontab myself: https://gist.github.com/jhofman/6772884

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment