Last change
on this file since 327 was 251, checked in by Rick van der Zwet, 14 years ago |
Grumble they mess around with tags.
|
-
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]
|
---|
[235] | 15 | clubpasnummer = sys.argv[3]
|
---|
[233] | 16 | except:
|
---|
[235] | 17 | print "Usage %s <username> <password> <clubpasnummer>" % 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
|
---|
[251] | 32 | m = re.search('<span class="sifr-header">([^<]*)<',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]
|
---|
| 38 | print "\n".join(numbers)
|
---|
| 39 | if any([clubpasnummer.endswith(x) for x in numbers]):
|
---|
| 40 | print "YES; een prijs!"
|
---|
| 41 | else:
|
---|
| 42 | print "NO; volgende week weer een kans"
|
---|
[233] | 43 | # Invalid HTML, else use the 'proper parser'
|
---|
| 44 | # import lxml
|
---|
| 45 | # root = lxml.etree.parse(response2)
|
---|
| 46 | # print lxml.etree.tostring(root.xpath(".//span[@class='sifr-header']")[0])
|
---|
Note:
See
TracBrowser
for help on using the repository browser.