This was inspired by https://medium.com/p/7f921ea94e8f. More info on how to use here: http://www.aamaliaa.com/post/62903197072/canihaziphone-js
Last active
December 24, 2015 11:59
-
-
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
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 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice---i went for a python crontab myself: https://gist.github.com/jhofman/6772884