Thursday, April 12, 2007

2007 yahoo fantasy baseball script

update 4/24/2007
Script updated. Fixed issues 3 and 6 reported by Rodric Rabbah and lots of code refactoring. The script no longer automatically loads the window. You have to activate it by pressing on the blue "Show Freebie Stats" button on the top right.

update 4/18/2007
Script updated. Fixed issues 4 and 5 reported by Ethan Herbertson.

update 4/16/2007 To use the script, follow these 3 steps

  1. download firefox
  2. install greasemonkey extension
  3. after installing greasemonkey, install the script

I just updated my fantasy baseball script for 2007. The most obvious change is that I incorporated the UI from my fantasy basketball script but there are also a bunch of under-the-hood fixes too. I go into some detail in those two blog postings on how the scripts are implemented so I won't recap any of that here but I will describe one bug fix. Stolen bases and homers are not part of the boxscore and they require extra parsing.

The stolen base string is of the form: D. Roberts 2 (2nd Inning off J. Bard), B. Bonds (3rd inning off J. Bard)

My old regular expression was a simple check to see if a players name was part of the string. The problem was that if I had J. Bard on my team, then he got a stolen base even though he was the one that allowed the steal. To fix the problem, I deleted everything in parentheses first.

That regular expression looks like: statLine = statLine.replace(/\([^\)].+?\)/gi,''); The key is '?' which makes it a non greedy match and [^\)] which tells the engine when to stop.

Another thing that bothered me was calling mozilla's childNodes method on a table row returned some unexpected results. Instead of returning a list of td elements, it would also return some additional children. To remedy this annoyance, I call row.getElementsByTagName("TD") and then I get a list of td elements that I expect. That said, I'm much happier with Mozilla's handling of the dom api and the development plugins available in FireFox. My day job is as web developer for a high traffic site where we strive for pixel, perfect perfection between IE 6,7 and firefox so developing for just one browser was a nice break.

Install the script.

17 comments:

Danie said...

Whoa dude, that rocks!! Thanks!!! :)

Kenton said...

It shows the stats for my team fine but its unable to show the stats for other mangers in my league? Is that something thats supposed to happen or can this only see the owners team? If possible i would like it to be able to see my opponents stats also.

Dave said...

kenton,
it should show stats for the other managers in your league but you need to go to their data management page. I'm in both a public and plus league this year and it works for me. anyone else having issues seeing their opponents stats?

Anonymous said...

when I click install script, the only thing that shows up is the actual script, Is there and actual link that I am supposed to click, because only doing that doesn't work. Thanks.

Anonymous said...

This is the same anonymous that posted at 2:19 PM. I was wondering if you could walk me through the steps on how to install the script, please be as simple as possible. Thanks.

YHW said...

I am also having trouble installing this. Same thing happens to me, as it does to the anonymous. It just loads up the script page..and nothing happens.

arf said...

I also cannot get it to work. Maybe we are all idiots, but some instructions would be helpful.

arf said...

ok i figured it out.

You need to goto https://addons.mozilla.org/en-US/firefox/addon/748

Install the greasemonkey on firefox and then click on the "install" button.

Its working great now!

Kenton said...

Yeah sorry dave i was using the drop down box to change users. When i clicked on the teams from the main page i was able to see the stats for their teams. Thanks for the help

YHW said...

thanks arf. that fixed the problem.

Dave said...

sorry about the confusion, I just updated this post with more instructions

thehumble said...

I can't get this to work. I've installed greasemonkey, I have an updated version of firefox, and I've installed this script and I can't get the "Show Free Stats" or whatever button to show up. Please help. Thanks!

Dave said...

thehumble, I made an update to the script so maybe that fixes your problem. The games need to in progress or over for the stats to appear.

bpk said...

Thanks for writing this, I was half way into editing your basketball stats script to work for baseball before I thought it would be wise to look if it'd already been done.

Allen said...

Good work David...
I have the script installed, it is working. However, not quite the way I expected to. Maybe you can tell me whether something is wrong or that it is the intended behavior.
1. When I start the stats, it gets a set of player's stats, but it does not update its stats unless I hit refresh
2. When I start the stats it gets a set of players. However when new games start, it does not pick the new players started playing. I have to close the window, refresh the Yahoo team page and restart the stats.

If this is the intended behavior, I hate to stay it, but it is cumbersome to use.

Dave said...

Hi Allen,

you can log bug or feature requests here:
http://code.google.com/p/freebiestats/issues/list

both of your issues could be solved if the script did an auto refresh but I never thought of implementing that. west coast bias I suppose since by the time I get home and start checking on my fantasy teams most games have already been completed.

Anonymous said...

Dave, just wondering if you knew of an API that would allow us to get our Yahoo! fantasy baseball league stats each day? I'm trying to write some C# code to do this. I've had marginal success (until today), but it's a total hack. Just wondering if you know of a better way to get fantasy baseball data from Yahoo!

Nice script, BTW.

Thanks,
/bc
blakeREMOVETHIS@caraways.net