Tech and travel

Using twill to check my lotto numbers

2007-12-06

Twill is, according to their website, a simple scripting language for Web browsing. It’s a language in it’s own right, but all the command can be called from within Python. Here’s an example :

from twill.commands import *

my_numbers=[
  [2, 4, 6, 8, 10, 12],
  [8, 10, 12, 14, 16, 18],
]

config("use_tidy", "0")
redirect_output("log.txt")

go('http://www.national-lottery.co.uk/player/p/results/results.do')

for row, l in enumerate(my_numbers):
    for i, value in enumerate(l):
        fv("quickCheckerForm",
           "longPlayslipForms[0].drawGameBoards[%i].numbersChosen[%i]" % (row,i),
           "%i" % value)

fv("quickCheckerForm", "drawSubTypeID", "1")
submit()

try:
    find("Congratulations")
    print "Won something !"
except:
    print "Nada"

This program checks lottery numbers (in the UK). The go() function opens a web page. Form fields are filled in then using the fv() (which stands for formvalue) function. Submitting the form is done using the submit() function.

The resulting page is then loaded. The find() function is used to check this page to see if it contains the string ‘Congratulations’ .

Twill has more functions, the language reference can be found here.

Copyright (c) 2024 Michel Hollands