Created
October 29, 2021 09:11
-
-
Save matthewhaworth/825e04aff2afa6d707c7c18af65858e0 to your computer and use it in GitHub Desktop.
iPhone Stock Detector
This file contains 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
/** | |
* I found the availability json by looking for XHR requests on this page: | |
* https://www.apple.com/uk/shop/iphone/iphone-upgrade-program | |
* | |
* I'm not completely sure if it will help if you're not using the upgrade program, but it does | |
* seem to have two flags for availability, 'unlocked' and 'contract'. | |
*/ | |
import fetch from 'node-fetch'; | |
const delay = ms => new Promise(resolve => setTimeout(resolve, ms)) | |
const stores = { | |
'R372': 'Leeds', | |
'R239': 'Liverpool', | |
'R215': 'Manchester', | |
'R136': 'Manchester' | |
} | |
const phones = { | |
'MLL93B/A': 'Blue 128GB', | |
'MLLE3B/A': 'Blue 256GB', | |
'MLL63B/A': 'Black 128GB', | |
'MLLA3B/A': 'Black 256GB', | |
} | |
const interests = [ | |
{ store: 'R372', phone: 'MLL93B/A' }, | |
{ store: 'R372', phone: 'MLLE3B/A' }, | |
{ store: 'R372', phone: 'MLL63B/A' }, | |
{ store: 'R372', phone: 'MLLA3B/A' }, | |
{ store: 'R239', phone: 'MLL93B/A' }, | |
{ store: 'R239', phone: 'MLLE3B/A' }, | |
{ store: 'R239', phone: 'MLL63B/A' }, | |
{ store: 'R239', phone: 'MLLA3B/A' }, | |
{ store: 'R215', phone: 'MLL93B/A' }, | |
{ store: 'R215', phone: 'MLLE3B/A' }, | |
{ store: 'R215', phone: 'MLL63B/A' }, | |
{ store: 'R215', phone: 'MLLA3B/A' }, | |
{ store: 'R136', phone: 'MLL93B/A' }, | |
{ store: 'R136', phone: 'MLLE3B/A' }, | |
{ store: 'R136', phone: 'MLL63B/A' }, | |
{ store: 'R136', phone: 'MLLA3B/A' }, | |
]; | |
const findiPhones = async function() { | |
while (true) { | |
const iphones = await fetch(`https://reserve-prime.apple.com/GB/en_GB/reserve/A/availability.json`).then(response => response.json()) | |
for (let i in interests) { | |
if (iphones.stores[interests[i].store][interests[i].phone].availability.contract || iphones.stores[interests[i].store][interests[i].phone].availability.unlocked) { | |
console.log(stores[interests[i].store] + ': ' + phones[interests[i].phone]); | |
} | |
} | |
await delay(1000); | |
} | |
} | |
findiPhones(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment