[ProPython] Python Masters

Author: Ed Leafe

Posted: 2006-04-07 at 15:08:34

No, I don't mean gurus. I mean what do you do when you're a golf nut

and want to keep up with the Masters tournament, going on since

yesterday (for those of you non-golfers). Well, this little Python

script I whipped up lets me run it occasionally from the terminal

window and see how players I'm interested in are doing. You can

change it to add any player you like.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

import re

import sys

import urllib

url="http://www.golfweb.com/tournaments/masters/leaderboard"

resp = urllib.urlopen(url).read()

if len(sys.argv) < 2:

nms = ["Tiger", "mickelson", "vijay", "Goosen", "couples"]

else:

nms = sys.argv[1:]

for nm in nms:

mtch = re.search("z\((.+%s.+)\);" % nm, resp, re.I)

try:

m = mtch.groups()[0]

x = m.split(",")

fullname = re.search(">([^<]+)<", x[4]).groups()[0]

pos = x[1].replace('"', '')

today = x[5].replace('"', '')

thru = x[6].replace('"', '').replace(" ", "")

score = x[7].replace('"', '')

if thru == "F":

hole = "He's in the clubhouse, and was %s on the day." % today

elif thru == "":

hole = "His tee time is at %s." % today

else:

hole = "He's %s today after %s holes" % (today, thru)

print "%s is at %s (position: %s). %s" % (fullname, score, pos, hole)

except:

print "No match for", nm

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Anyways, if you're a golf fan, try this with whatever names you

like. If you're not a golf fan, you can marvel at how little code it

took to do this!

-- Ed Leafe

-- http://leafe.com

-- http://dabodev.com

©2006 Ed Leafe