Skip to content

Instantly share code, notes, and snippets.

@dominikwilkowski
Created November 3, 2021 20:10
Show Gist options
  • Save dominikwilkowski/d25b1fa5fafea4c8a4ec2f078fdb6afa to your computer and use it in GitHub Desktop.
Save dominikwilkowski/d25b1fa5fafea4c8a4ec2f078fdb6afa to your computer and use it in GitHub Desktop.
Monitor Apple in-store pickup
import fetch from 'node-fetch';
import twilio from 'twilio';
const URL = 'https://www.apple.com/au/shop/fulfillment-messages?parts.0=Z0YQ&location=2093&mt=regular&option.0=ML8X3X%2FA%2CMKUV3FE%2FA&_=1634013871312';
const ACCOUNTSID = 'XXX'; // TODO fill me
const AUTHTOKEN = 'XXX'; // TODO fill me
function alertMe({ storeName, storePickupQuote }) {
const client = new twilio(ACCOUNTSID, AUTHTOKEN);
client.messages
.create({
body: `APPLE ALERT: 🚨🚨🚨 ${storeName} -> ${storePickupQuote}`,
to: 'XXX', // TODO fill me
from: 'XXX', // TODO fill me
});
}
async function checkStores() {
let found = false;
process.stdout.write(`${new Date().toString()} `);
let result;
let data;
try {
result = await fetch(URL);
data = await result.json();
} catch(error) {
process.stdout.write('\u001b[41m failed \u001b[0m\n');
setTimeout(checkStores, 30000);
return;
}
data
.body
.content
.pickupMessage
.stores
.forEach(({ storeName, partsAvailability: { Z0YQ: { storePickupQuote }}}) => {
if(!storePickupQuote.startsWith('Unavailable') && !storePickupQuote.startsWith('Currently unavailable') && storePickupQuote !== 'Apple Store Pickup is currently unavailable') {
process.stdout.write('\u001b[42m FOUND \u001b[0m\n');
console.log(`🚨🚨🚨 ${storeName} -> ${storePickupQuote}`);
// alertMe({ storeName, storePickupQuote });
found = true;
}
});
if(!found) {
process.stdout.write('\u001b[41m nope \u001b[0m\n');
setTimeout(checkStores, 30000);
}
}
checkStores();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment