Created
October 1, 2024 14:26
-
-
Save danjohnson95/e85b791ee46cabf900553d47c84c31a8 to your computer and use it in GitHub Desktop.
iphone-stock.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const stores = { | |
"R363": "Aberdeen, Union Square", | |
"R482": "Basingstoke, Festival Place", | |
"R335": "Bath, SouthGate", | |
"R313": "Belfast, Victoria Square", | |
"R118": "Birmingham, Birmingham", | |
"R244": "Brighton, Churchill Square", | |
"R252": "Bristol, Bristol", | |
"R393": "Bristol, Cribbs Causeway", | |
"R496": "Bromley, Bromley", | |
"R270": "Cambridge, Grand Arcade", | |
"R334": "Cardiff, Cardiff", | |
"R328": "Edinburgh, Edinburgh", | |
"R279": "Exeter, Princesshay", | |
"R423": "Gateshead, Metrocentre", | |
"R340": "Glasgow, Braehead", | |
"R135": "Glasgow, Glasgow", | |
"R242": "Grays, Lakeside", | |
"R113": "Greenhithe, Bluewater", | |
"R227": "Kingston upon Thames, Bentall Centre", | |
"R372": "Leeds, Trinity Leeds", | |
"R308": "Leicester, Highcross", | |
"R239": "Liverpool, Liverpool", | |
"R762": "London, Battersea", | |
"R163": "London, Brent Cross", | |
"R329": "London, Brompton Road", | |
"R245": "London, Covent Garden", | |
"R092": "London, Regent Street", | |
"R410": "London, Stratford City", | |
"R226": "London, White City", | |
"R215": "Manchester, Manchester Arndale", | |
"R136": "Manchester, Trafford Centre", | |
"R269": "Milton Keynes, Milton Keynes", | |
"R341": "Newcastle upon Tyne, Eldon Square", | |
"R391": "Norwich, Norwich", | |
"R545": "Plymouth, Plymouth", | |
"R176": "Reading, The Oracle", | |
"R153": "Sheffield, Meadowhall", | |
"R255": "Solihull, Touchwood Centre", | |
"R174": "Southampton, Southampton", | |
"R527": "Watford, Watford", | |
} | |
const getAvailabilityForModel = async (model) => { | |
const req = fetch('https://reserve-prime.apple.com/GB/en_GB/reserve/A/availability.json') | |
const availability = await (await req).json() | |
const storeAvailability = [] | |
const storeIdentifiers = Object.keys(availability.stores) | |
storeIdentifiers.forEach(storeIdentifier => { | |
const storeName = stores[storeIdentifier] | |
const modelsForStore = Object.keys(availability.stores[storeIdentifier]) | |
modelsForStore.forEach(modelForStore => { | |
if (modelForStore === model) { | |
storeAvailability.push({ | |
storeName, | |
availability: availability.stores[storeIdentifier][modelForStore].availability | |
}) | |
} | |
}) | |
}) | |
return storeAvailability | |
} | |
(async () => { | |
const availabilityForModel = (await getAvailabilityForModel('MYNE3QN/A')) | |
const storesWithAvailability = availabilityForModel.filter(({availability}) => availability.contract || availability.unlocked) | |
if (storesWithAvailability.length > 0) { | |
console.log('Stores with availability:\n -', storesWithAvailability.map(({storeName}) => storeName).join('\n - ')) | |
} else { | |
console.log('No stores with availability') | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment