-
-
Save harperreed/6940386 to your computer and use it in GitHub Desktop.
updated to check all models in a specific zip
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
#!/usr/bin/env python | |
# | |
# file: scrapple.py | |
# | |
# description: checks apple.come for iphone 5s in-store pickup availability | |
# | |
# usage: ./scrapple.py [zip] | |
# | |
# or in a crontab: | |
# */5 * * * * /path/to/scrapple.py 10012 && mailx -s 5s [email protected] | |
# | |
import sys | |
from urllib import urlencode | |
from urllib2 import urlopen | |
import json | |
carrier_codes = {'att': 305, | |
'verizon': 341, | |
'sprint': 350} | |
storage_offset = {'16': 0, | |
'32': 3, | |
'64': 6} | |
color_offset = {'grey': 0, | |
'silver': 1, | |
'gold': 2} | |
BASE_URL = 'http://store.apple.com/us/retail/availabilitySearch' | |
def get_part_num(carrier, storage, color): | |
num = carrier_codes[carrier] + storage_offset[storage] + color_offset[color] | |
return 'ME%dLL/A' % num | |
if __name__ == '__main__': | |
zip = sys.argv[1] | |
print "Looking for iphones in " + zip | |
p = 0 | |
stores = [] | |
phones = {} | |
print "crawling apple.", | |
for carrier in carrier_codes: | |
for storage in storage_offset: | |
for color in color_offset: | |
k = '%s %sGB %s' % (carrier, storage, color) | |
phones[k] = [] | |
part_num = get_part_num(carrier, storage, color) | |
query = urlencode({'parts.0': part_num, 'zip': zip}) | |
url = '%s?%s' % (BASE_URL, query) | |
response = json.load(urlopen(url)) | |
print ".", | |
for store in response['body']['stores']: | |
availability = store["partsAvailability"][part_num]["pickupDisplay"] | |
if availability != "unavailable": | |
phones[k].append(store["storeDisplayName"]) | |
print "\nResults:\n" | |
for k, v in phones.iteritems(): | |
if len(v) > 0: | |
print k | |
for p in v: | |
print "\t" + p | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment