source: misc/geluksnummers-donaldduck.py@ 275

Last change on this file since 275 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
RevLine 
[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>
8import mechanize
9import re
10import sys
11
12try:
13 username = sys.argv[1]
14 password = sys.argv[2]
[235]15 clubpasnummer = sys.argv[3]
[233]16except:
[235]17 print "Usage %s <username> <password> <clubpasnummer>" % sys.argv[0]
[233]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
[251]32m = re.search('<span class="sifr-header">([^<]*)<',response2.read())
[233]33if not m:
34 print "Something is wrong, unable to find the geluksnummers"
35 sys.exit(1)
36
[235]37numbers = [n for n in re.split('\s*-\s*', m.group(1)) if n]
38print "\n".join(numbers)
39if any([clubpasnummer.endswith(x) for x in numbers]):
40 print "YES; een prijs!"
41else:
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.