Index
2006-04-07 15:08Ed Leafe : [ProPython] Python Masters
2006-04-07 15:21Kevin Cully : Re: [ProPython] Python Masters
2006-04-07 16:02Matthew Jarvis : Re: [ProPython] Python Masters
Back to top
[ProPython] Python Masters

Author: Ed Leafe

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

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
Back to top
Re: [ProPython] Python Masters

Author: Kevin Cully

Posted: 2006-04-07 15:21:16   Link

Thanks Ed! I'm not a golf fan, but I was a caddie in my younger years.

I copied your email into a text document called master.py and from the

shell prompt in MEPIS, typed in "python masters.py" and just like an

unladen sparrow, there were the results!

Awesome.

Kevin Cully

CULLY Technologies, LLC

Sponsor of Fox Forward 2006!

http://foxforward.net

Ed Leafe wrote:

> 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

>

>

>

>

>

[excessive quoting removed by server]

©2006 Kevin Cully
Back to top
Re: [ProPython] Python Masters

Author: Matthew Jarvis

Posted: 2006-04-07 16:02:56   Link

>

> 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!

>

Nicely done Ed!

Truly amazing what some other languages (besides VFP) can do...

Matt Jarvis

©2006 Matthew Jarvis