Skip to content

Instantly share code, notes, and snippets.

@bamdadd
Last active October 19, 2021 08:56
Show Gist options
  • Save bamdadd/ad326a8a5fec7cef8358dbead587b86e to your computer and use it in GitHub Desktop.
Save bamdadd/ad326a8a5fec7cef8358dbead587b86e to your computer and use it in GitHub Desktop.
Apple UK iphone 13 inventory check
from time import sleep
import mac_say
import requests
from pprint import pprint
def is_available(y):
return y[1] != 'unavailable'
def get_availabilities(postcode, part_number):
headers = {
'authority': 'www.apple.com',
'sec-ch-ua': '"Chromium";v="94", "Google Chrome";v="94", ";Not A Brand";v="99"',
'sec-ch-ua-mobile': '?0',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36',
'sec-ch-ua-platform': '"macOS"',
'accept': '*/*',
'sec-fetch-site': 'same-origin',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
'referer': 'https://www.apple.com/uk/shop/buy-iphone/iphone-13-pro/6.1-inch-display-256gb-graphite',
'accept-language': 'en-GB,en-US;q=0.9,en;q=0.8',
}
params = (
('pl', 'true'),
('mt', 'compact'),
('parts.0', part_number),
('location', postcode),
)
response = requests.get('https://www.apple.com/uk/shop/fulfillment-messages', headers=headers,
params=params)
content = response.json()
availabilities = list(
map(lambda x: (
x['address']['address'], x['partsAvailability'][part_number]['pickupDisplay']),
content['body']['content']['pickupMessage']['stores']))
all_avails = list(map(lambda s: [is_available(s), s[0]], availabilities))
return list(filter(lambda x: x[0], all_avails))
while True:
availabilities = get_availabilities(postcode='n1 1ab',
part_number='MLVE3B/A')
if availabilities:
pprint(availabilities)
mac_say.say("found")
print('---------------------')
sleep(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment