-
-
Save kccheung/c1ea33fd90c408915345ae86dc74d124 to your computer and use it in GitHub Desktop.
Tiny script to scrape Apple Online Store every second and check for changes in MacBook availability
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
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