Skip to content

Instantly share code, notes, and snippets.

@kgadek
Created January 25, 2014 01:43
Show Gist options
  • Save kgadek/8610472 to your computer and use it in GitHub Desktop.
Save kgadek/8610472 to your computer and use it in GitHub Desktop.
'Tallica: Seek and buy
#!/usr/bin/env python
# coding=utf-8
import os
from bs4 import BeautifulSoup
import requests
import time
import itertools
url = ("http://www.eventim.pl/Bilety-sonisphere-warszawa.html?affiliate=LNP&fun=evdetail"
"&doc=evdetailb&key=1089581$3516336&jumpIn=yTix&fromPromoWithEridRestriction=true")
def notify(dct):
os.system('terminal-notifier ' + ' '.join('{0} "{1}"'.format(k, v) for k, v in dct.iteritems()))
for notify_nothing in itertools.cycle([True] + [False] * 11):
try:
r = requests.get(url)
txt = BeautifulSoup(r.text).find_all(id="tableAssortmentList")[0]
txt = txt.findAll("td", text="Golden Circle ")[0]
txt = txt.nextSibling.nextSibling.text.strip()
while txt != u"Brak dostępnych biletów":
notify({"-title": "Metallica: Seek and Buy",
"-subtitle": "Sonisphere 2014",
"-sound": "default",
"-message": "!! CHYBA COŚ JEST !!",
"-open": "http://ow.ly/sW04z"})
time.sleep(30)
if notify_nothing:
notify({"-title": "Metallica: Seek and Buy",
"-subtitle": "Sonisphere 2014",
"-message": "Tak tylko informuję, że nadal sprawdzam",
"-open": "http://ow.ly/sW04z"})
except (requests.ConnectionError, IndexError):
notify({"-title": "Metallica: Seek and Buy",
"-subtitle": "Sonisphere 2014",
"-sound": "default",
"-message": "LOLWUT? Poszedł wyjątek. Proszę, sprawdź co się stało…",
"-open": "http://ow.ly/sW04z"})
except:
notify({"-title": "Metallica: Seek and Buy",
"-subtitle": "Sonisphere 2014",
"-sound": "default",
"-message": "LOLWUT? Poszedł >nieprzewidziany< wyjątek. Proszę, sprawdź co się stało…",
"-open": "http://ow.ly/sW04z"})
time.sleep(5 * 60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment