#!/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] clubpasnummers = 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] for clubpasnummer in clubpasnummers: print "Geluksnummers van deze week:", ",".join(numbers) if any([clubpasnummer.endswith(x) for x in numbers]): print "[%s] YES; heeft een prijs!" % clubpasnummer else: print "[%s] HELAAS; volgende week weer een kans" % clubpasnummer