Skip to content

Instantly share code, notes, and snippets.

@alexbain alexbain/iphone-checker.py
Last active Aug 29, 2015

Embed
What would you like to do?
iPhone inventory checker
# Couple notes here:
# 0) Apple might change their APIs. If they do, this won't work any more.
# 1) If you want a different model iPhone, you'll have to do some sleuthing on apple.com "check availability" network requests to figure out what to look for.
import requests
import twilio
import sys
import time
import twilio.rest
account_sid = ""
auth_token = ""
def check_iphone():
sys.stdout.flush()
# 6+ 64GB space gray
# r = requests.get('http://store.apple.com/us/retailStore/availabilitySearch?parts.0=MGAU2LL%2FA&zip=94108')
# 6 64gb space gray
r = requests.get('http://store.apple.com/us/retailStore/availabilitySearch?parts.0=MG4W2LL%2FA&zip=94108')
# ['stores'][0] is downtown SF Apple store
# Also, be sure to update the part number ('MG4W2LL/A') if you change the GET request above
available = r.json()['body']['stores'][0]['partsAvailability']['MG4W2LL/A']['pickupDisplay']
if available == "available":
client = twilio.rest.TwilioRestClient(account_sid, auth_token)
for number in ["+14155551212", "+14155551213"]:
message = client.messages.create(
body="iPhone6 64GB is now in stock at SF Apple Store",
to=number,
from_="+1415551000"
)
print "AVAILABLE"
return True
else:
print "NOT AVAILABLE"
return False
while not check_iphone():
time.sleep(60)
[program:iphone_checker]
command=/home/USER/iphone-checker/venv/bin/python /home/USER/iphone-checker/checker.py
autorestart=unexpected
stdout_logfile=/var/log/iphone-checker.log
redirect_stderr=true
stopsignal=QUIT
@alexbain

This comment has been minimized.

Copy link
Owner Author

alexbain commented Apr 10, 2015

The iphone_checker.conf is a supervisord conf script that will restart the script if it crashes, but not if it exits with exit code 0.

@alexbain

This comment has been minimized.

Copy link
Owner Author

alexbain commented Apr 10, 2015

Couple other notes:

  • requests and twilio are external python libraries that must be installed with pip
  • The supervisord conf expects a virtualenv setup in a venv directory. If you install the pip packages globally, you can use the system python instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.