Skip to content

Instantly share code, notes, and snippets.

@kccheung kccheung/mbp.py forked from drx/mbp.py
Created Aug 13, 2016

Embed
What would you like to do?
Tiny script to scrape Apple Online Store every second and check for changes in MacBook availability
import urllib2
import re
import time
import pycurl
import StringIO
#url = "http://78.10.81.103:19100/mbp.html"
url = "http://store.apple.com/pl/browse/home/shop_mac/family/macbook_pro/select"
prev_delivery = (None, None)
while True:
#f = urllib2.urlopen(url)
#html = f.read()
b = StringIO.StringIO()
c = pycurl.Curl()
c.setopt(pycurl.URL, url)
c.setopt(pycurl.PROXY, 'localhost')
c.setopt(pycurl.PROXYPORT, 40000)
c.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5)
c.setopt(pycurl.WRITEFUNCTION, b.write)
c.perform()
html = b.getvalue()
delivery = re.findall('<li class="description">\s*[^/]*?<sup>1</sup>\s*</li>.*?<span class="customer_commit_display">(.*?)</span>', html, re.S)
for i in range(len(delivery)):
if delivery[i] != prev_delivery[i]:
print 'Change: ', delivery
for j in range(5):
print('\a'*5)
time.sleep(0.5)
break
prev_delivery = delivery
print time.strftime("%H:%M:%S")
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.