mirror of
https://github.com/Giu-zhao/ios_rule_script
synced 2024-11-22 08:28:25 +08:00
[AppleStore]增加MacbookPro库存监控
This commit is contained in:
parent
c0bfb34c43
commit
9aaaebd0fd
@ -15,6 +15,7 @@ function getGoodsStock(parts, location, option = "") {
|
||||
url = encodeURI(`https://www.apple.com.cn/shop/fulfillment-messages?pl=true&mt=compact&parts.0=${parts}&location=${location}&_=${new Date().getTime()}`);
|
||||
}
|
||||
magicJS.get(url, (err, resp, data) => {
|
||||
try{
|
||||
let obj = JSON.parse(data);
|
||||
let stores = obj["body"]["content"]["pickupMessage"]["stores"];
|
||||
if (stores) {
|
||||
@ -23,6 +24,11 @@ function getGoodsStock(parts, location, option = "") {
|
||||
magicJS.notify("查询库存失败,请检查配置是否正确。");
|
||||
resolve([]);
|
||||
}
|
||||
}
|
||||
catch (err){
|
||||
magicJS.logError(`解析库存数据失败,异常信息:${err}`);
|
||||
resolve([]);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -31,8 +37,10 @@ async function watchStock(goods_models, applestore_region) {
|
||||
let stock = magicJS.read(APPLESTORE_STOCK_KEY);
|
||||
stock = !!stock ? stock : {};
|
||||
let len = goods_models.length;
|
||||
let tasks = [];
|
||||
|
||||
for (let i = 0; i < len; i++) {
|
||||
const wrap = async () =>{
|
||||
let partsConfig = goods_models[i].split("#");
|
||||
let parts = partsConfig[0];
|
||||
let option = partsConfig.length >= 2 ? partsConfig[1] : "";
|
||||
@ -120,7 +128,10 @@ async function watchStock(goods_models, applestore_region) {
|
||||
magicJS.logInfo(logStr);
|
||||
}
|
||||
}
|
||||
tasks.push(wrap());
|
||||
}
|
||||
|
||||
await Promise.all(tasks);
|
||||
// 存储本次库存检查结果
|
||||
magicJS.write(APPLESTORE_STOCK_KEY, stock);
|
||||
}
|
||||
@ -141,11 +152,12 @@ async function watchStock(goods_models, applestore_region) {
|
||||
// 监控库存
|
||||
await watchStock(goods_models, applestore_region);
|
||||
|
||||
if (magicJS.isNode) {
|
||||
while (6 <= new Date().getHours() <= 23) {
|
||||
while (magicJS.isNode) {
|
||||
let hours = new Date().getHours()
|
||||
if (hours <= 1 || hours >= 6){
|
||||
await watchStock(goods_models, applestore_region);
|
||||
await magicJS.sleep(3000);
|
||||
}
|
||||
await magicJS.sleep(5000);
|
||||
}
|
||||
|
||||
magicJS.done();
|
||||
|
Loading…
Reference in New Issue
Block a user