-
Notifications
You must be signed in to change notification settings - Fork 0
/
steps.js
95 lines (82 loc) · 3.2 KB
/
steps.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
let timerId;
const finderFun = async function finder() {
try {
console.log("calling finderfun......");
audio = new Audio('https://freesound.org/data/previews/403/403019_5121236-lq.mp3');
const proUrl = "";
const iphone14pro = [
// IPHONE 14 PRO........
// "MPVH3LL/A",
//purple
"MQ0E3LL/A", "MQ1D3LL/A", "MQ273LL/A", "MQ303LL/A",
//gold
"MQ063LL/A", "MQ163LL/A", "MQ213LL/A", "MQ2T3LL/A",
// silver
"MQ003LL/A", "MQ0X3LL/A", "MQ1U3LL/A", "MQ2L3LL/A",
// black
"MPXT3LL/A", "MQ0N3LL/A", "MQ1K3LL/A", "MQ2E3LL/A",
];
const iphone14proMax = [
// IPHONE 14 PROMAX........
//purple
"MQ8R3LL/A", "MQ8W3LL/A", "MQ913LL/A", "MQ953LL/A",
//gold
"MQ8Q3LL/A", "MQ8V3LL/A", "MQ903LL/A", "MQ943LL/A",
// silver
"MQ8P3LL/A", "MQ8U3LL/A", "MQ8Y3LL/A", "MQ933LL/A",
// black
"MQ8N3LL/A", "MQ8N3LL/A", "MQ8N3LL/A", "MQ923LL/A"
]
const iPhoneModelsCode = [
...iphone14pro,
...iphone14proMax
];
const requestPromises = [];
var responses = await Promise.all(
iPhoneModelsCode.map(
code =>
fetch(`https://www.apple.com/shop/fulfillment-messages?pl=true&mts.0=regular&mts.1=compact&cppart=UNLOCKED/US&parts.0=${code}&searchNearby=true&store=R039`, {
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
// 'Content-Type': 'application/x-www-form-urlencoded',
},
}).then(
(response) =>{
if(response.ok){
return response && response.json()
} else {
return {}
}
}
)));
console.log("responses.........", responses);
const goodStores = [];
let productName;
for (let j = 0; j < responses.length; j++) {
const productCode = iPhoneModelsCode[j];
if(responses[j] && responses[j].body){
const stores = responses[j].body.content.pickupMessage.stores;
for (let k = 0; k < stores.length; k++) {
let isAvailable = stores[k].partsAvailability[productCode].pickupDisplay === "available";
if (isAvailable) {
productName = stores[k].partsAvailability[productCode].messageTypes.compact.storePickupProductTitle;
goodStores.push({ store: stores[k].makeReservationUrl, productName });
}
}
}
}
if (goodStores.length) {
console.log("available in these stores..............");
audio.play();
console.table(goodStores);
clearInterval(timerId);
} else {
console.log("no store found..............");
}
} catch (e) {
console.log("error",e);
}
}
finderFun();
timerId = setInterval(finderFun,20000);