Last active
August 29, 2015 14:06
-
-
Save cyanly/209a7988d157b178feb9 to your computer and use it in GitHub Desktop.
nodejs iPhone6 UK-GB availability check
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('superagent'); | |
var stores = {}; | |
var models = { | |
'MGA82ZP/A': 'iPhone 6 Plus 16G Grey ', | |
'MGA92ZP/A': 'iPhone 6 Plus 16G Silver', | |
'MGAA2ZP/A': 'iPhone 6 Plus 16G Gold ', | |
'MGAH2ZP/A': 'iPhone 6 Plus 64G Grey ', | |
'MGAJ2ZP/A': 'iPhone 6 Plus 64G Silver', | |
'MGAK2ZP/A': 'iPhone 6 Plus 64G Gold ', | |
'MGAC2ZP/A': 'iPhone 6 Plus 128G Grey ', | |
'MGAE2ZP/A': 'iPhone 6 Plus 128G Silver', | |
'MGAF2ZP/A': 'iPhone 6 Plus 128G Gold ', | |
'MG472ZP/A': 'iPhone 6 16G Grey ', | |
'MG482ZP/A': 'iPhone 6 16G Silver', | |
'MG492ZP/A': 'iPhone 6 16G Gold ', | |
'MG4F2ZP/A': 'iPhone 6 64G Grey ', | |
'MG4H2ZP/A': 'iPhone 6 64G Silver', | |
'MG4J2ZP/A': 'iPhone 6 64G Gold ', | |
'MG4A2ZP/A': 'iPhone 6 128G Grey ', | |
'MG4C2ZP/A': 'iPhone 6 128G Silver', | |
'MG4E2ZP/A': 'iPhone 6 128G Gold ', | |
'MGA82B/A': 'iPhone 6 Plus 16G Grey ', | |
'MGA92B/A': 'iPhone 6 Plus 16G Silver', | |
'MGAA2B/A': 'iPhone 6 Plus 16G Gold ', | |
'MGAH2B/A': 'iPhone 6 Plus 64G Grey ', | |
'MGAJ2B/A': 'iPhone 6 Plus 64G Silver', | |
'MGAK2B/A': 'iPhone 6 Plus 64G Gold ', | |
'MGAC2B/A': 'iPhone 6 Plus 128G Grey ', | |
'MGAE2B/A': 'iPhone 6 Plus 128G Silver', | |
'MGAF2B/A': 'iPhone 6 Plus 128G Gold ', | |
'MG472B/A': 'iPhone 6 16G Grey ', | |
'MG482B/A': 'iPhone 6 16G Silver', | |
'MG492B/A': 'iPhone 6 16G Gold ', | |
'MG4F2B/A': 'iPhone 6 64G Grey ', | |
'MG4H2B/A': 'iPhone 6 64G Silver', | |
'MG4J2B/A': 'iPhone 6 64G Gold ', | |
'MG4A2B/A': 'iPhone 6 128G Grey ', | |
'MG4C2B/A': 'iPhone 6 128G Silver', | |
'MG4E2B/A': 'iPhone 6 128G Gold '}; | |
var lastUpdated = undefined; | |
function check() { | |
var getsome = false; | |
request | |
.get('https://reserve.cdn-apple.com/GB/en_GB/reserve/iPhone/availability.json') | |
//.get('https://reserve.cdn-apple.com/HK/en_HK/reserve/iPhone/availability.json') | |
.end(function(res){ | |
if (res.body && res.body.updated) { | |
var data = res.body; | |
if (lastUpdated != data.updated) { | |
lastUpdated = data.updated; | |
delete data.updated; | |
for(var key in data) { | |
for(var subkey in data[key]) | |
if (data[key][subkey] == true) { | |
if (!getsome) | |
console.log(new Date()); | |
getsome = true; | |
var storeName = key; | |
var modelName = subkey; | |
if (stores.hasOwnProperty(key)) | |
storeName = stores[key]; | |
if (models.hasOwnProperty(subkey)) | |
modelName = models[subkey]; | |
console.log('!!! ', storeName, ' - ', modelName); | |
} | |
} | |
} | |
} | |
setTimeout(check, 5000); | |
}); | |
} | |
//Get store names dictionary | |
request | |
.get('https://reserve.cdn-apple.com/GB/en_GB/reserve/iPhone/stores.json') | |
.end(function(res){ | |
if (res.body && res.body.stores) { | |
var data = res.body.stores; | |
for (var i = data.length - 1; i >= 0; i--) { | |
var store = data[i]; | |
stores[store.storeNumber] = store.storeName; | |
}; | |
//Start checking for availability | |
check(); | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment