Monday, June 20, 2016

MLB.com Fantasy Baseball Score Checker

I've been hacking away on a project for my fantasy baseball league. MLB.com's fantasy baseball has its daily scoreboard in flash, so it doesn't work on mobile.

Not only did I want to check my score on mobile, I thought having easily accessible scores on mobile would make things more engaging for the whole league!

I wrote a python script to scrape values from MLB servers and display them in a simple interface:

This league has classy team names. 
The basic flow of the script is:
  1. Get the fantasy league schedule JSON data from this URL:
    http://www.mlb.com/fantasylookup/json/named.fb_index_schedule.bam?league_id=1514
    Note the league_id can be found with CTRL-F if you "view source" on your league homepage.
  2. Process the fantasy league schedule and build a big Python dictionary called this_week (I should have built a class - maybe that's on the todo list). This step figures out all of the fantasy team_id's that belong to your league_id.
    Also, build each team's roster based on the fantasy team roster data. The period_id comes from the schedule data, and the player_ids come from here:
    http://www.mlb.com/fantasylookup/json/named.fb_team_lineup.bam?&team_id=9972&period_id=13
  3. Figure out which games are being currently played in real life. This can be done by counting the number of folders containing matching regex gid_[0-9]{4}_[0-9]{2}_[0-9]{2}[a-z0-9_]* from this directory:
    http://gdx.mlb.com/components/game/mlb/year_2016/month_04/day_25/ (substitute today's date)
    Specifically, we are looking for the boxscore.json files for each game:
    http://gdx.mlb.com/components/game/mlb/year_2016/month_04/day_25/gid_2016_04_25_chamlb_tormlb_1/boxscore.json
    We are going to use these to calculate the fantasy points for each player's real-life stats.
  4. Grab every boxscore.json file for today's real-life games, read the data and build a monster dictionary called super_boxscore.
  5. Loop through all of the fantasy player rosters in the this_week variable,  and look up the player_ids in the super_boxscore variable. Calculate fantasy points for each player_id.
  6. Show the results!
I wrote most of this blog post a month ago, intending to add more features and make a richer blog post. Sadly, like many of my projects it has stalled at nowhere near completion and I have not put in any time over the last 4-5 weeks! 

But if you are running an MLB.com fantasy league and you want a better mobile interface for your members, check out my project on Github: https://github.com/b-neufeld/mlb-fantasy-checker 

29 comments:

  1. Do you mind if I quote a few of your articles as long as I provide credit and sources back to your blog? My blog site is in the very same area of interest as yours and my visitors would definitely benefit from some of the information you provide here. Please let me know if this alright with you. Thank you!uwell nunchaku kit

    ReplyDelete
  2. Valuable info. Lucky me I found your web site by accident, and I'm shocked why this accident did not happened earlier! I bookmarked it. sec 3 physics tuition

    ReplyDelete
  3. When I originally commented I clicked the "Notify me when new comments are added" checkbox and now each time a comment is added I get three e-mails with the same comment. Is there any way you can remove people from that service? Thanks! roller blinds

    ReplyDelete
  4. I am curious to find out what blog platform you have been working with? I'm having some minor security problems with my latest site and I would like to find something more risk-free. Do you have any suggestions? internet marketing

    ReplyDelete
  5. Lovely blog! I am loving it!! Will be back later to read some more. I am bookmarking your feeds also.Hello. remarkable job. I did not expect this. This is a excellent story. Thanks! best domains in Singapore

    ReplyDelete
  6. You actually make it appear so easy with your presentation but I to find this topic to be really something which I feel I might by no means understand. It sort of feels too complex and very vast for me. I am looking forward in your next submit, I’ll try to get the hang of it! infographics for websites

    ReplyDelete
  7. Hi there! I know this is kinda off topic however , I'd figured I'd ask. Would you be interested in trading links or maybe guest writing a blog post or vice-versa? My blog goes over a lot of the same subjects as yours and I believe we could greatly benefit from each other. If you are interested feel free to shoot me an e-mail. I look forward to hearing from you! Excellent blog by the way!singapore domain name

    ReplyDelete
  8. Hi there! This is my first visit to your blog! We are a group of volunteers and starting a new initiative in a community in the same niche. Your blog provided us useful information to work on. You have done a marvellous job! responsive website development

    ReplyDelete
  9. Hi! I know this is somewhat off topic but I was wondering if you knew where I could find a captcha plugin for my comment form? I'm using the same blog platform as yours and I'm having difficulty finding one? Thanks a lot..arbitration lawyer singapore

    ReplyDelete
  10. Good post but I was wanting to know if you could write a litte more on this subject? I'd be very thankful if you could elaborate a little bit more. Thanks! high potency fish oil

    ReplyDelete
  11. Hi there, i read your blog occasionally and i own a similar one and i was just curious if you get a lot of spam feedback? If so how do you reduce it, any plugin or anything you can recommend? I get so much lately it's driving me mad so any assistance is very much appreciated. company formation services in Singapore

    ReplyDelete
  12. Thanks , I have just been searching for info approximately this topic for ages and yours is the greatest I have came upon till now. However, what concerning the conclusion? Are you sure in regards to the supply? venue hotel

    ReplyDelete
  13. Howdy! This is my first visit to your blog! We are a team of volunteers and starting a new project in a community in the same niche. Your blog provided us beneficial information to work on. You have done a outstanding job! landed property painting


    ReplyDelete
  14. Does your site have a contact page? I'm having a tough time locating it but, I'd like to send you an email. I've got some creative ideas for your blog you might be interested in hearing. Either way, great site and I look forward to seeing it grow over time. Youtube marketing in Singapore

    ReplyDelete
  15. Currently it sounds like Movable Type is the best blogging platform out there right now. (from what I've read) Is that what you're using on your blog? best exterminator nyc

    ReplyDelete
  16. Hey! This is my first comment here so I just wanted to give a quick shout out and tell you I really enjoy reading through your posts. Can you suggest any other blogs/websites/forums that cover the same topics? Thanks a lot! maps.google.com.sg

    ReplyDelete
  17. Thanks so much for providing individuals with an extremely memorable possiblity to read from this blog. It is often so enjoyable and also jam-packed with a great time for me and my office peers to visit your web site at the very least three times in a week to read through the newest tips you have. And lastly, I am also certainly fulfilled with the effective points you serve. Selected 4 facts in this post are surely the most impressive we have all had. webdesign

    ReplyDelete
  18. Wonderful blog! I found it while browsing on Yahoo News. Do you have any tips on how to get listed in Yahoo News? I've been trying for a while but I never seem to get there! Appreciate it
    marketing agencies singapore

    ReplyDelete
  19. I am not sure where you're getting your information, but great topic. I needs to spend some time learning much more or understanding more. Thanks for magnificent information I was looking for this information for my mission. singapore chocolate brands

    ReplyDelete
  20. Hmm is anyone else experiencing problems with the images on this blog loading? I'm trying to figure out if its a problem on my end or if it's the blog. Any feedback would be greatly appreciated. nearby dental clinic

    ReplyDelete
  21. Magnificent site. Plenty of useful info here. I’m sending it to a few friends ans also sharing in delicious. And certainly, thanks for your sweat! search engine rankings

    ReplyDelete
  22. Thanks a lot for giving everyone an exceptionally splendid opportunity to discover important secrets from here. It's usually so lovely plus packed with a lot of fun for me and my office mates to visit your blog at the least 3 times weekly to study the latest guidance you have. Not to mention, I'm so usually astounded with the breathtaking creative concepts you serve. Selected 1 ideas on this page are really the most efficient we've ever had. google digital marketing course

    ReplyDelete
  23. Hey would you mind letting me know which webhost you're using? I've loaded your blog in 3 completely different browsers and I must say this blog loads a lot quicker then most. Can you suggest a good internet hosting provider at a reasonable price? Kudos, I appreciate it!Candid wedding photographers in Chennai

    ReplyDelete
  24. Hi there! Would you mind if I share your blog with my zynga group? There's a lot of people that I think would really appreciate your content. Please let me know. Many thanks. used concrete pumps

    ReplyDelete
  25. Interesting blog! Is your theme custom made or did you download it from somewhere? A theme like yours with a few simple tweeks would really make my blog shine. Please let me know where you got your theme. Appreciate it
    starting an online business in singapore

    ReplyDelete
  26. Right now it sounds like Drupal is the preferred blogging platform out there right now. (from what I've read) Is that what you're using on your blog?

    ReplyDelete
  27. I have learn several just right stuff here. Certainly value bookmarking for revisiting. I surprise how much effort you set to create this kind of magnificent informative site.
    marketing strategies

    ReplyDelete
  28. This design is spectacular! You definitely know how to keep a reader entertained. Between your wit and your videos, I was almost moved to start my own blog (well, almost...HaHa!) Wonderful job. I really loved what you had to say, and more than that, how you presented it. Too cool! inbound marketing

    ReplyDelete
  29. I'm curious to find out what blog system you are using? I'm having some minor security problems with my latest website and I would like to find something more safeguarded. Do you have any suggestions? seo courses

    ReplyDelete