#!/usr/bin/env python # # Simple hack to automatically retrieve the digital 'geluksnummers' voor # donaldduck.nl to see whether you won a price (run it every week). # # Licence: BSDLike - http://rickvanderzwet.nl/LICENSE # Rick van der Zwet import mechanize import re import sys try: username = sys.argv[1] password = sys.argv[2] clubpasnummer = sys.argv[3] except: print "Usage %s " % sys.argv[0] sys.exit(1) # Login br = mechanize.Browser() br.open('http://www.donaldduck.nl/clubhuis/inloggen/') br.select_form(name="login") br['data[email]'] = username br['data[password]'] = password # Find the geluksnummers paginae response1 = br.submit() response2 = br.follow_link(url_regex="geluksnummers") # Find the numbers itself m = re.search('([^<]*)<',response2.read()) if not m: print "Something is wrong, unable to find the geluksnummers" sys.exit(1) numbers = [n for n in re.split('\s*-\s*', m.group(1)) if n] print "\n".join(numbers) if any([clubpasnummer.endswith(x) for x in numbers]): print "YES; een prijs!" else: print "NO; volgende week weer een kans" # Invalid HTML, else use the 'proper parser' # import lxml # root = lxml.etree.parse(response2) # print lxml.etree.tostring(root.xpath(".//span[@class='sifr-header']")[0])