|
var rp = require('request-promise'); |
|
var moment = require('moment'); |
|
|
|
var storesURL = function(localtion){ |
|
return 'https://reserve-prime.apple.com/'+localtion+'/zh_'+localtion+'/reserve/iPhoneX/stores.json'; |
|
} |
|
var availabilityURL = function(localtion){ |
|
return 'https://reserve-prime.apple.com/'+localtion+'/zh_'+localtion+'/reserve/iPhoneX/availability.json'; |
|
}; |
|
|
|
var location = ['CN','HK']; |
|
|
|
var options = { |
|
uri: storesURL, |
|
headers: { |
|
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/604.3.1 (KHTML, like Gecko) Version/11.0.1 Safari/604.3.1' |
|
}, |
|
json: true |
|
}; |
|
var kDeviceName = { |
|
'MQA92CH/A':'iPhone X 256GB 银色', |
|
'MQA82CH/A':'iPhone X 256GB 深空灰', |
|
'MQA52CH/A':'iPhone X 64GB 深空灰', |
|
'MQA62CH/A':'iPhone X 64GB 银色' |
|
} |
|
var kStoreName = { |
|
|
|
}; |
|
|
|
function getAvailableString(info){ |
|
var availability = info.availability; |
|
var ret = ''; |
|
if (availability.contract) { |
|
ret = ret + '有合约机 '; |
|
} |
|
if (availability.unlocked) { |
|
ret = ret + '有解锁机 '; |
|
} |
|
return ret; |
|
} |
|
function getTSString(ts) { |
|
var timestamp = moment.unix(ts/1000).format("YYYY MMMM Do, hh:mm:ss a"); |
|
return timestamp; |
|
} |
|
|
|
var checkStatus = function(localtion){ |
|
options.uri = storesURL(localtion); |
|
rp(options).then( stores =>{ |
|
console.log('预约URL: '+'https://reserve-prime.apple.com/CN/zh_CN/reserve/iPhoneX/availability?channel=1'); |
|
var shops = stores.stores; |
|
shops.forEach(elem => { |
|
kStoreName[elem.storeNumber] = elem; |
|
}); |
|
var timestamp = getTSString(stores.config.updatedTime); |
|
return shops; |
|
}).then(shops =>{ |
|
options.uri = availabilityURL(localtion); |
|
var shopsNum = []; |
|
shops.forEach(elem => { |
|
shopsNum.push(elem.storeNumber); |
|
}); |
|
rp(options).then( fengX =>{ |
|
var timestamp = getTSString(fengX.updated); |
|
console.log('Updated Time: ',timestamp); |
|
var allShops = fengX.stores; |
|
for (let i = 0; i < shopsNum.length; i++) { |
|
var shopId = shopsNum[i]; |
|
var devices = allShops[shopId]; |
|
for (let deviceKey in devices) { |
|
var info = devices[deviceKey]; |
|
var status = getAvailableString(info); |
|
if (status.length > 0) { |
|
var city = kStoreName[shopId].city; |
|
var store = kStoreName[shopId].storeName; |
|
store = store.replace(city,""); |
|
console.log(city+' '+store+'\t\t'+kDeviceName[deviceKey] +'\t'+ status); |
|
} |
|
} |
|
} |
|
}) |
|
}) |
|
} |
|
|
|
var location = process.argv[2]; |
|
setInterval(function () { |
|
if (location == "CN" || location == "cn") { |
|
checkStatus('CN'); |
|
}else{ |
|
checkStatus('HK'); |
|
} |
|
process.stdout.write('\033c'); |
|
}, 3000); |