Created
May 10, 2020 12:13
-
-
Save WillBishop/39ad083441ca0c7eb41680b98bf76cb4 to your computer and use it in GitHub Desktop.
Get stock from Apple with a postcode and part number
This file contains hidden or 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
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