Skip to content

Instantly share code, notes, and snippets.

@michaellzc
Last active September 25, 2023 03:53
Show Gist options
  • Select an option

  • Save michaellzc/3e3e3397dfcacf76b870a7d2f85cfcb9 to your computer and use it in GitHub Desktop.

Select an option

Save michaellzc/3e3e3397dfcacf76b870a7d2f85cfcb9 to your computer and use it in GitHub Desktop.
Check iPhone 15 Pro Max Stock in Vancouver, Canada
"""
Usage:
# Show help
# Look up part number and store number
python main.py --help
# Check iPhone 15 Pro Max 512GB Natural Titanium at Apple Store Richmond Centre (default)
python main.py -model MTUG3VC/A -store R421
"""
import requests
import argparse
import json
import datetime
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36",
"Connection": "keep-alive",
"Pragma": "no-cache",
"Cache-Control": "no-cache",
}
name_to_part_number = {
"iPhone 15 Pro Max 256GB Natural Titanium": "MU6R3VC/A",
"iPhone 15 Pro Max 512GB Natural Titanium": "MU6W3VC/A",
"iPhone 15 Pro Max 1TB Natural Titanium": "MU713VC/A",
"iPhone 15 Pro Max 256GB Blue Titanium": "MU6T3VC/A",
"iPhone 15 Pro Max 512GB Blue Titanium": "MU6X3VC/A",
"iPhone 15 Pro Max 1TB Blue Titanium": "MU723VC/A",
"iPhone 15 Pro Max 256GB White Titanium": "MU6Q3VC/A",
"iPhone 15 Pro Max 512GB White Titanium": "MU6V3VC/A",
"iPhone 15 Pro Max 1TB White Titanium": "MU703VC/A",
"iPhone 15 Pro 256GB Blue Titanium": "MTUG3VC/A",
}
part_number_to_name = {v: k for k, v in name_to_part_number.items()}
store_name_to_number = {
"Richmond Centre": "R421",
"Metrotown": "R460",
"Guildford Town Centre": "R601",
"Coquitlam Centre": "R488",
"Pacific Centre": "R280",
}
store_number_to_name = {v: k for k, v in store_name_to_number.items()}
search_endpoint = "https://www.apple.com/ca/shop/fulfillment-messages"
new_line = "\n"
def main():
parser = argparse.ArgumentParser(
description="Check iPhone 15 Pro stock in Vancouver, Canada",
formatter_class=argparse.RawTextHelpFormatter,
)
parser.add_argument(
"-model",
type=str,
help=f"""Available models:
{f"{new_line}".join([f"- {v} ({k})" for k, v in name_to_part_number.items()])}
""",
)
parser.add_argument(
"-store",
type=str,
help=f"""Available stores:
{f"{new_line}".join([f"- {v} ({k})" for k, v in store_name_to_number.items()])}
""",
)
args = parser.parse_args()
if args.model is None:
part_number = name_to_part_number["iPhone 15 Pro Max 512GB Natural Titanium"]
else:
part_number = args.model
if args.store is None:
store_number = store_name_to_number["Richmond Centre"]
else:
store_number = args.store
print(f"Checking part number: {part_number}, store number: {store_number}")
resp = requests.get(
search_endpoint,
headers=headers,
params={
"pl": "true",
"parts.0": part_number,
"store": store_number,
"searchNearby": "true",
},
)
if not resp.ok:
print("Error: ", resp.text)
return
with open(f"./{datetime.datetime.now().strftime('%Y-%m-%d-%H-%M')}.json", "w") as f:
json.dump(resp.json(), f, indent=2)
stores = resp.json()["body"]["content"]["pickupMessage"]["stores"]
for store in stores:
availability = store["partsAvailability"][part_number]
if availability["pickupDisplay"] == "available":
print(
f"{part_number_to_name[part_number]} is available for pick up at Apple Store {store['storeName']} (quote: {availability['pickupSearchQuote']}, type: {availability['pickupType']})",
)
else:
print(
f"{part_number_to_name[part_number]} is not available at Apple Store {store['storeName']}",
)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment