Created
September 20, 2022 09:59
-
-
Save kxalex/4d67530eb7e8453e63e76b870233de18 to your computer and use it in GitHub Desktop.
iPhone checkers checks for iPhone 14 Pro available stocks
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 time | |
import os | |
import subprocess | |
# MQ103ZP/A - S 256GB | |
# MQ0T3ZP/A - SB 256GB | |
# | |
# MQ1W3ZP/A - S 512GB | |
# MQ1M3ZP/A - SG 512GB | |
class bcolors: | |
HEADER = '\033[95m' | |
OKBLUE = '\033[94m' | |
OKCYAN = '\033[96m' | |
OKGREEN = '\033[92m' | |
WARNING = '\033[93m' | |
FAIL = '\033[91m' | |
ENDC = '\033[0m' | |
BOLD = '\033[1m' | |
UNDERLINE = '\033[4m' | |
postcode = '2000' | |
models_to_check = ["MQ103ZP/A", "MQ0T3ZP/A"] | |
# models_to_check = ["MMXL3X/A"] | |
models = { | |
"MQ103ZP/A": "iPhone 14 Pro 256GB Silver", | |
"MQ0T3ZP/A": "iPhone 14 Pro 256GB Space Black", | |
"MMXL3X/A": "iPhone SE 128GB (PRODUCT)RED" | |
} | |
def notify(message, title=None, subtitle=None, soundname=None): | |
""" | |
Display an OSX notification with message title an subtitle | |
sounds are located in /System/Library/Sounds or ~/Library/Sounds | |
displayNotification("message","title","subtitle","Pop") | |
displayNotification("message","title","subtitle") | |
displayNotification("message","title") | |
displayNotification("message") | |
""" | |
title_part = '' | |
if title is not None: | |
title_part = 'with title "{0}"'.format(title) | |
subtitle_part = '' | |
if subtitle is not None: | |
subtitle_part = 'subtitle "{0}"'.format(subtitle) | |
soundname_part = '' | |
if soundname is not None: | |
soundname_part = 'sound name "{0}"'.format(soundname) | |
apple_script_notification = 'display notification "{0}" {1} {2} {3}'.format(message, title_part, subtitle_part, | |
soundname_part) | |
os.system("osascript -e '{0}'".format(apple_script_notification)) | |
def sound(text="iPhone 14 Pro in stock"): | |
subprocess.Popen(["say", "'" + text + "'"]) | |
def check_stock(model): | |
# r = requests.get('https://www.apple.com/au/shop/pickup-message-recommendations?location=' + postcode + '&product=' + model) | |
r = requests.get('https://www.apple.com/au/shop/fulfillment-messages?pl=true&mts.0=regular&parts.0=' + model + '&location=' + postcode) | |
json_data = r.json() | |
if r.status_code != 200: | |
print(r.status_code) | |
# stores = json_data['body']['PickupMessage']['stores'] | |
content = json_data['body']['content'] | |
# print(content) | |
stores = content['pickupMessage']['stores'] | |
for store in stores: | |
print(store['storeName'] + ": ", end='') | |
if store['partsAvailability'] != {}: | |
try: | |
# print(store['partsAvailability'].get(model)) | |
available_model = store['partsAvailability'][model] | |
if available_model['pickupDisplay'] != 'unavailable': | |
print(bcolors.OKGREEN + "Yes" + bcolors.ENDC, end='') | |
product_title_ = available_model['messageTypes']['regular']['storePickupProductTitle'] | |
title_ = store['storeName'] + " has " + product_title_ | |
notify("iPhone 14 Pro in stock", title_) | |
sound(title_) | |
else: | |
print(bcolors.BOLD + "No" + bcolors.ENDC, end='') | |
except KeyError: | |
print(bcolors.BOLD + "No, but found these models" + bcolors.ENDC) | |
for part in store['partsAvailability']: | |
# sound("Some iPhone in stock") | |
print(" " + part, end=': ') | |
print(store['partsAvailability'][part]['messageTypes']['regular']['storePickupProductTitle']) | |
else: | |
print(bcolors.BOLD + "No" + bcolors.ENDC, end='') | |
print("") | |
counter = 0 | |
print("Getting data at: " + str(time.strftime("%I:%M:%S %p"))) | |
while True: | |
for model in models_to_check: | |
print("\033[1m" + model + ": " + models[model] + "\033[0m") | |
check_stock(model) | |
print("Waiting 10 seconds; " + str(counter) + " times") | |
counter += 1 | |
print("\033[A\033[A\033[A\033[A\033[A\033[A\033[A\033[A\033[A\033[A") | |
print("\033[A\033[A\033[A\033[A\033[A\033[A\033[A\033[A\033[A\033[A") | |
print("\033[A\033[A\033[A\033[A\033[A\033[A") | |
time.sleep(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment