Skip to content

Instantly share code, notes, and snippets.

@jhofman
Last active November 12, 2017 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhofman/619eb31d08c45da0decf944b3896ea81 to your computer and use it in GitHub Desktop.
Save jhofman/619eb31d08c45da0decf944b3896ea81 to your computer and use it in GitHub Desktop.
checks apple.come for iphone x in-store pickup availability
#!/usr/bin/env python
#
# file: scrapple_x.py
#
# description: checks apple.come for iphone x in-store pickup availability
#
# usage: ./scrapple.py [zip] [att|verizon|sprint|tmobile] [64|256] [grey|silver]
#
# or in a crontab:
# */5 * * * * /path/to/scrapple.py 12345 tmobile 64 grey && mailx -s "iphone x" 2125551212@vtext.com
#
import sys
from urllib import urlencode
from urllib2 import urlopen
import json
import smtplib
# https://www.techwalls.com/iphone-x-models-a1865-a1901-a1902-differences/
models = {
'att': {'silver': {'64': 'MQAK2LL/A', '256': 'MQAK2LL/A'},
'grey': {'64': 'MQAJ2LL/A','256': 'MQAM2LL/A'}},
'tmobile': {'silver': {'64': 'MQAR2LL/A', '256': 'MQAV2LL/A'},
'grey': {'64': 'MQAQ2LL/A','256': 'MQAU2LL/A'}},
'sprint': {'silver': {'64': 'MQCT2LL/A', '256': 'MQCW2LL/A'},
'grey': {'64': 'MQCR2LL/A','256': 'MQCV2LL/A'}},
'verizon': {'silver': {'64': 'MQCL2LL/A', '256': 'MQCP2LL/A'},
'grey': {'64': 'MQCK2LL/A','256': 'MQCN2LL/A'}}
}
BASE_URL = 'https://www.apple.com/shop/pickup-message-recommendations'
if __name__=='__main__':
if len(sys.argv) != 5:
print "usage: %s [zip] [att|verizon|sprint|tmobile] [64|256] [grey|silver]" % sys.argv[0]
sys.exit(1)
zipcode, carrier, storage, color = sys.argv[1:]
part_num = models[carrier][color][storage]
query = urlencode({'product': part_num, 'location': zipcode})
url = '%s?%s' % (BASE_URL, query)
response = json.load(urlopen(url))
stores = []
for store in response['body']['PickupMessage']['stores']:
availability = store["partsAvailability"]
if availability != {}:
stores.append((store["address"]["address"], availability))
if len(stores) > 0:
msg = '%s %sGB %s\n' % (carrier, storage, color)
msg += "\n".join([": ".join(store) for store in stores])
print msg
sys.exit(0)
else:
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment