Last change
on this file since 372 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
|
Rev | Line | |
---|
[233] | 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>
|
---|
| 8 | import mechanize
|
---|
| 9 | import re
|
---|
| 10 | import sys
|
---|
| 11 |
|
---|
| 12 | try:
|
---|
| 13 | username = sys.argv[1]
|
---|
| 14 | password = sys.argv[2]
|
---|
[348] | 15 | clubpasnummers = sys.argv[3:]
|
---|
[233] | 16 | except:
|
---|
[348] | 17 | print "Usage %s <username> <password> <clubpasnummer> [<clubpasnummer2> <clubpasnummer3> ...]" % sys.argv[0]
|
---|
[233] | 18 | sys.exit(1)
|
---|
| 19 |
|
---|
| 20 | # Login
|
---|
| 21 | br = mechanize.Browser()
|
---|
| 22 | br.open('http://www.donaldduck.nl/clubhuis/inloggen/')
|
---|
| 23 | br.select_form(name="login")
|
---|
| 24 | br['data[email]'] = username
|
---|
| 25 | br['data[password]'] = password
|
---|
| 26 |
|
---|
| 27 | # Find the geluksnummers paginae
|
---|
| 28 | response1 = br.submit()
|
---|
| 29 | response2 = br.follow_link(url_regex="geluksnummers")
|
---|
| 30 |
|
---|
| 31 | # Find the numbers itself
|
---|
[348] | 32 | m = re.search('<span class="cufon-diary">([^<]*)<',response2.read())
|
---|
[233] | 33 | if not m:
|
---|
| 34 | print "Something is wrong, unable to find the geluksnummers"
|
---|
| 35 | sys.exit(1)
|
---|
| 36 |
|
---|
[235] | 37 | numbers = [n for n in re.split('\s*-\s*', m.group(1)) if n]
|
---|
[348] | 38 | for 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.