Skip to content

Instantly share code, notes, and snippets.

@WillBishop
Created May 10, 2020 12:13
Show Gist options
  • Save WillBishop/39ad083441ca0c7eb41680b98bf76cb4 to your computer and use it in GitHub Desktop.
Save WillBishop/39ad083441ca0c7eb41680b98bf76cb4 to your computer and use it in GitHub Desktop.
Get stock from Apple with a postcode and part number
import requests
import json
import datetime
import time
import sys
import os
params = (
('parts.0', '%s/A' % sys.argv[1]),
('location', sys.argv[2]),
)
while True:
response = requests.get('https://www.apple.com/au/shop/retail/pickup-message', params=params)
js = json.loads(response.text)
stores = js["body"]["stores"]
storeNames = [x["storeName"] for x in stores]
minSpacing = len(max(storeNames, key=len))
os.system("cls")
print("Last Updated", datetime.datetime.now())
for store in stores:
availability = store["partsAvailability"][params[0][1]]["pickupDisplay"]
spacing = minSpacing - len(store["storeName"])
print(store["storeName"], " " * spacing, availability)
time.sleep(60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment