Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Script to check stock at apple stores
For more part numbers for other phone models etc, look here:
import requests
import urllib
PARTS = {'verizon': {'silver': {'16G': 'MLM02LL/A', '64G': 'MLMG2LL/A'},
'gray': {'16G': 'MLLY2LL/A', '64G': 'MLMF2LL/A'},
'gold': {'16G': 'MLY52LL/A', '64G': 'MLY72LL/A'},
'rose': {'16G': 'MLY62LL/A', '64G': 'MLY82LL/A'}},
'at&t': {'silver': {'16G': 'MLLM2LL/A', '64G': 'MLM52LL/A'},
'gray': {'16G': 'MLLL2LL/A', '64G': 'MLM42LL/A'},
'gold': {'16G': 'MLXH2LL/A', '64G': 'MLXK2LL/A'},
'rose': {'16G': 'MLXJ2LL/A', '64G': 'MLXL2LL/A'}},
'unlocked': {'silver': {'16G': 'MLLX2LL/A', '64G': 'MLME2LL/A'},
'gray': {'16G': 'MLLW2LL/A', '64G': 'MLMD2LL/A'},
'gold': {'16G': 'MLY12LL/A', '64G': 'MLY32LL/A'},
'rose': {'16G': 'MLY22LL/A', '64G': 'MLY42LL/A'}}}
def make_reverse_lookup():
lookup = {}
for carrier in PARTS:
for color in PARTS[carrier]:
for storage in PARTS[carrier][color]:
lookup[PARTS[carrier][color][storage]] = "{} {} {}".format(carrier, color, storage)
return lookup
def build_url(part_number_list, zipcode):
query_dict = {'location': zipcode}
for i, part in enumerate(part_number_list):
query_dict['parts.'+str(i)] = part
query = urllib.parse.urlencode(query_dict)
return BASE_URL + query
def check_stock(url, max_stores=5):
lookup = make_reverse_lookup()
response = requests.get(url)
data = response.json()
for store in data['body']['stores'][:max_stores]:
for part, status in store['partsAvailability'].items():
print("{:20} {:10} at {}".format(lookup[part], status['pickupDisplay'], store['storeDisplayName']))
if __name__ == "__main__":
zipcode = '02138'
partslist = [PARTS['verizon']['silver']['64G'],
url = build_url(partslist, zipcode)
check_stock(url, max_stores=5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.