Skip to content

Instantly share code, notes, and snippets.

@pengx17
Created September 15, 2018 07:02
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 pengx17/6b74522c545105a97bac2661c1a62b84 to your computer and use it in GitHub Desktop.
Save pengx17/6b74522c545105a97bac2661c1a62b84 to your computer and use it in GitHub Desktop.
Check iPhone Xs Max
const { get, post } = require("axios");
const url = `https://sc.ftqq.com/SCU15511Ta62845f53fed1f23c365071e0e1bda035a029f383eba8.send`;
const getParams = (text, desp) => encodeURI(`?text=${text}&desp=${desp}`);
async function getBeijingStores() {
const res = await get(
"https://reserve-prime.apple.com/CN/zh_CN/reserve/iPhone/stores.json"
);
return res.data.stores.filter(store => store.city === "北京");
}
async function checkAvailable(stores) {
const res = await get(
"https://reserve-prime.apple.com/CN/zh_CN/reserve/iPhone/availability.json"
);
const deviceids = ["MT742CH/A", "MT762CH/A", "MT752CH/A"]; // 黑,金,白
const devicenames = ["黑", "金", "白"];
const storeAndAvail = stores.map(store => ({
store: store.storeName,
available: deviceids
.map(
(id, i) =>
res.data.stores[store.storeNumber][id].availability.unlocked
? devicenames[i]
: ""
)
.filter(name => !!name)
}));
const availableStore = storeAndAvail.filter(
({ available }) => available.length > 0
);
console.log(storeAndAvail);
if (availableStore.length > 0) {
const text = "有货啦 ~ " + new Date().toLocaleTimeString();
const desp = availableStore
.map(avail => `${avail.store}: ${avail.available.join(", ")}`)
.join("\n\n");
post(url + getParams(text, desp));
}
}
(async () => {
const beijingStores = await getBeijingStores();
setInterval(() => checkAvailable(beijingStores), 5000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment