Last active
August 29, 2015 14:08
-
-
Save alexbain/d914dbff7473daaa0520 to your computer and use it in GitHub Desktop.
iPhone inventory checker
This file contains 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
# 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) |
This file contains 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
[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 |
Couple other notes:
requests
andtwilio
are external python libraries that must be installed withpip
- The supervisord conf expects a
virtualenv
setup in avenv
directory. If you install thepip
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
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.