Created
November 26, 2013 23:22
-
-
Save lyonanderson/7668088 to your computer and use it in GitHub Desktop.
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
import urllib2 | |
import urllib | |
from re import findall | |
import json | |
request = urllib2.Request('https://ireserve.apple.com/GB/en_GB/reserve/iPad/productReservation') | |
request.add_header('Accept','text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8') | |
response = urllib2.urlopen(request) | |
responsString = str(response.read()) | |
cTokenPlacer = findall("var securityCToken = \"(.*)\";", responsString) | |
stores = findall("var states = \[(.*)\];", responsString) | |
storesJSON = json.loads(str(stores[0])) | |
if (len(cTokenPlacer) == 1): | |
cookie = response.headers.get('Set-Cookie') | |
for storeJSON in storesJSON['stores']: | |
city = storeJSON['city']['name'] | |
hasShownStoreName = False | |
data = urllib.urlencode({'tag' : 'iPad', 'store' : storeJSON['number'], 'product' : 'iPad mini with Retina display' }); | |
request = urllib2.Request('https://ireserve.apple.com/GB/en_GB/reserve/iPad/skusForStoreProduct', data) | |
request.add_header('cookie', cookie) | |
request.add_header('cToken', cTokenPlacer[0]) | |
request.add_header('Host', 'ireserve.apple.com') | |
request.add_header('Accept', 'application/json, text/javascript, */*; q=0.01') | |
request.add_header('X-Requested-With', 'XMLHttpRequest') | |
request.add_header('Origin', 'https://ireserve.apple.com') | |
request.add_header('User-Agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9) AppleWebKit/537.71 (KHTML, like Gecko) Version/7.0 Safari/537.71') | |
request.add_header('Referer', 'https://ireserve.apple.com/GB/en_GB/reserve/iPad/productReservation') | |
response = urllib2.urlopen(request) | |
skus = json.load(response) | |
ipads = skus['productResponse']['productGroupedSku']['iPad mini with Retina display'] | |
for colour, kinds in ipads.iteritems(): | |
for kind, availability in kinds.iteritems(): | |
for capicity, status in availability['Unlocked'].iteritems(): | |
if (status[0]['enabled']): | |
if (hasShownStoreName != True): | |
print "\n" + city + " " + storeJSON['name'] + "\n" | |
hasShownStoreName = True | |
print colour + " " + kind + " - " + capicity | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment