Last active
August 29, 2015 14:16
-
-
Save rahulg/abd827bd8e54f3107d9e to your computer and use it in GitHub Desktop.
Poll the Apple Store for shipping status of the 12" MacBook
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 | |
# coding: utf-8 | |
import json | |
import re | |
import sys | |
try: | |
import urllib.request as _urllib | |
except ImportError: | |
import urllib2 as _urllib | |
try: | |
region = sys.argv[1] | |
except IndexError: | |
region = 'sg_edu_4911' | |
r = _urllib.urlopen('http://store.apple.com/{0}/buy-mac/macbook/space-grey-256gb'.format(region)) | |
html = r.read().decode('utf-8') | |
status_text = re.compile(r'^\s+window\.productSelectionController\.addData\((.*)\);$') | |
status_str = '' | |
for line in html.split('\n'): | |
m = status_text.match(line) | |
if m: | |
status_str = m.group(1) | |
break | |
status_block = json.loads(status_str) | |
for product in status_block['products']: | |
print( | |
'{0} {1} = {2}'.format(product['dimensionCapacity'], product['dimensionColor'], product['displayShippingQuote']) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment