Created
August 28, 2012 09:34
-
-
Save tomviner/3496566 to your computer and use it in GitHub Desktop.
Homemade 2012 ticket notifier
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
curl -O http://python-distribute.org/distribute_setup.py | |
python distribute_setup.py | |
curl -O http://pypi.python.org/packages/source/p/pip/pip-0.7.2.tar.gz | |
tar xzf pip-0.7.2.tar.gz | |
cd pip-0.7.2 | |
python setup.py install | |
easy_install pip | |
pip install requests |
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 time | |
import hashlib | |
import tempfile | |
import subprocess | |
import webbrowser | |
import requests | |
# webbrowser.open blocks on some OSs | |
USE_WEBB = True | |
SLEEP_TIME = 55 #secs | |
# URL of the search results page you're interested in | |
url = 'http://www.tickets.london2012.com/browse?form=search&tab=para&sport=&venue=50&fromDate=2012-09-01&toDate=2012-09-01&morning=1&afternoon=1&evening=1&show_available_events=1' | |
# put on some camouflage | |
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1'} | |
def web_browser_open(url): | |
if USE_WEBB: | |
webbrowser.open_new_tab(url) | |
else: | |
subprocess.Popen(['google-chrome', url]) | |
seen = set() | |
while True: | |
r = requests.get(url, headers=headers) | |
bytes = r.content | |
html = r.text | |
hash = hashlib.sha1(bytes).hexdigest()[:10] | |
print '%d chars (%s) %s' % (len(html), hash, time.asctime()) | |
if hash not in seen: | |
with tempfile.NamedTemporaryFile('w', delete=False) as temp_file: | |
temp_file.write(html.encode('utf-8')) | |
web_browser_open(url) | |
time.sleep(2) | |
web_browser_open(temp_file.name) | |
seen.add(hash) | |
time.sleep(SLEEP_TIME) | |
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
requests>=0.13.8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment