Skip to content

Instantly share code, notes, and snippets.

@saman
Last active October 29, 2021 10:54
Show Gist options
  • Save saman/e758f30326089885d14d5c01103798ff to your computer and use it in GitHub Desktop.
Save saman/e758f30326089885d14d5c01103798ff to your computer and use it in GitHub Desktop.
Apple Availability Checker
# This script can check apple website for availability of a prodcut in stores close to a zip code
# After finding availability it can send a notification via telegram
import telebot
import requests
# depends on the store this phrase can be different
not_avaliable = "Derzeit nicht verfügbar"
# make a telegram bot and put the token here
telegram_bot_token = ""
# the user id/channel username of telegram for recivieng messages
user_id = ""
bot = telebot.TeleBot(telegram_bot_token, parse_mode="MARKDOWN")
# models which you want to check
models = ['MLVE3ZD/A', 'MLLA3ZD/A', 'MLVH3ZD/A', 'MLLF3ZD/A']
# the zip code
zip_code = ''
# URL of Apple Store in Germany
url = 'https://www.apple.com/de/shop/fulfillment-messages?pl=true&mt=compact&location=' + zip_code
for i in range(len(models)):
url+='&parts.' + str(i) + '=' + models[i]
response = requests.post(url)
data = response.json()
output = ''
check = False
if data and data['head'] and data['head']['status'] == '200':
if data['body']['content']['pickupMessage']['stores']:
for store in data['body']['content']['pickupMessage']['stores']:
print('')
print(store['storeName'])
output += '[' + store['storeName'] +'](' + store['reservationUrl'] + ')' + '\n\r'
for part in store['partsAvailability']:
partData = store['partsAvailability'][part]
if partData['pickupSearchQuote'] != not_avaliable:
check = True
output += partData['storePickupProductTitle'] + ': ' + partData['pickupSearchQuote'] + '\n\r'
print(partData['storePickupProductTitle'] +':', partData['pickupSearchQuote'])
output += '\n\r'
else:
print('no store')
else:
print('no data')
if check:
try:
bot.send_message(user_id, output, disable_web_page_preview=True)
except:
print('bot couldn\'t send a message')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment