source: misc/geluksnummers-donaldduck.py@ 351

Last change on this file since 351 was 348, checked in by Rick van der Zwet, 13 years ago

Response got changed.

  • Property svn:executable set to *
File size: 1.3 KB
Line 
1#!/usr/bin/env python
2#
3# Simple hack to automatically retrieve the digital 'geluksnummers' voor
4# donaldduck.nl to see whether you won a price (run it every week).
5#
6# Licence: BSDLike - http://rickvanderzwet.nl/LICENSE
7# Rick van der Zwet <info@rickvanderzwet.nl>
8import mechanize
9import re
10import sys
11
12try:
13 username = sys.argv[1]
14 password = sys.argv[2]
15 clubpasnummers = sys.argv[3:]
16except:
17 print "Usage %s <username> <password> <clubpasnummer> [<clubpasnummer2> <clubpasnummer3> ...]" % sys.argv[0]
18 sys.exit(1)
19
20# Login
21br = mechanize.Browser()
22br.open('http://www.donaldduck.nl/clubhuis/inloggen/')
23br.select_form(name="login")
24br['data[email]'] = username
25br['data[password]'] = password
26
27# Find the geluksnummers paginae
28response1 = br.submit()
29response2 = br.follow_link(url_regex="geluksnummers")
30
31# Find the numbers itself
32m = re.search('<span class="cufon-diary">([^<]*)<',response2.read())
33if not m:
34 print "Something is wrong, unable to find the geluksnummers"
35 sys.exit(1)
36
37numbers = [n for n in re.split('\s*-\s*', m.group(1)) if n]
38for clubpasnummer in clubpasnummers:
39 print "Geluksnummers van deze week:", ",".join(numbers)
40 if any([clubpasnummer.endswith(x) for x in numbers]):
41 print "[%s] YES; heeft een prijs!" % clubpasnummer
42 else:
43 print "[%s] HELAAS; volgende week weer een kans" % clubpasnummer
Note: See TracBrowser for help on using the repository browser.