Jump to content

Request: Fangraphs (MLB) workflow


Recommended Posts

I'd really like to be able to pull certain baseball statistics into the Alfred window. For example, if I wanted to know a player's batting average or wOBA, I'd like to be able to open Alfred, type a keyword and the player's name and have it appear. I'm thinking it would be somewhat similar to the Rotten Tomatoes workflow, which pulls relevant information.

 

Could anyone help with this? Much thanks for any help.

Link to comment

Something like this may be possible. 

 

Is http://www.fangraphs.com the site that you are wanting to pull the data from? I don't see mention of an API on the site but, looking at the source code, it looks like you could send a request here: http://www.fangraphs.com/quickplayersearch.aspx?name={query} to get a list of matching players (to generate results like you were talking about). It would require parsing a little html but there isn't much in the resulting page so, it wouldn't be too tough. From there you could link to the players page or preview that page really quickly with quicklook (pressing Shift with the item selected in Alfred).

Link to comment

Thanks, yes it's fangraphs.com. I'm sorry, but I'm new to Alfred and am not really sure what you mean here. Any chance you could help me out as I'm trying to learn the software as quickly as I can. Thanks.

 

Try this out.

 

The keyword is 'fg', so type 'fg <player name>', as you type their name, it should provide a list of matching results in Alfred. You can press enter on a result to open that players page on fangraphs.com or you can press Shift with a player selected to get a quick preview of their stats.

 

Download

Link to comment

That's fantastic. Thanks a lot.

 

David, could I then take the files in the workflow folder to set up a similar workflow for another site? Would it be as simple as replacing the fangraphs.com with the link for searching on another site?

 

Thanks so much for your help.

Link to comment

That's fantastic. Thanks a lot.

 

David, could I then take the files in the workflow folder to set up a similar workflow for another site? Would it be as simple as replacing the fangraphs.com with the link for searching on another site?

 

Thanks so much for your help.

 

Unfortunately it wouldnt. The reason being is, I didn't see notice of an API or anything like that for fangraphs.com so I looked through their code to see how they built the search suggestions on the home page. Requesting a certain link returns an html table of data, I used Simple HTML Dom Parser (php library) to parse the html and create the results for you. Another site would have to be set up identically for you to just change the url on this and it work there as well.

Link to comment
  • 4 years later...

This has been my most used workflow and I can't thank you guys enough, but anyone know why this might be broken after the update to macOS High Sierra. I type in fg (player name) and it goes to a google search instead of the player page on Fangraphs.com. Thanks a lot for the help. 

Link to comment
1 hour ago, dmick89 said:

it goes to a google search

 

That is Alfred's default behaviour when a workflow fails. Essentially, all that says is "it's broken", which is no help at all with diagnosing the actual problem.

 

Please read the thread on how to report issues with workflows:

If you post an error report with the requested information, there is a much better chance that someone will be able to actually tell what's wrong, and therefore that your issue will be fixed.

Link to comment

Thank you.

 

I opened Alfred and entered fg Kris Bryant to search for Kris Bryant's stats on Fangraphs using the workflow linked earlier in this thread (latest version). Rather than bringing up his page so I could hit enter and be taken to his page in Safari, it just went back to the default google search. I'm running Alfred v 3.5 [876] and have just updated to macOS High Sierra. Here is what I get with the debugger. Thanks for any and all help. 

 

Starting debug for 'FanGraphs'

[2017-09-28 12:49:30][ERROR: input.scriptfilter] Code 255: Warning: file_get_contents(): stream does not support seeking in /Users/####/Desktop/Alfred/Alfred.alfredpreferences/workflows/user.workflow.####/simple_html_dom.php on line 75

Warning: file_get_contents(): Failed to seek to position -1 in the stream in /Users/####/Desktop/Alfred/Alfred.alfredpreferences/workflows/user.workflow.####/simple_html_dom.php on line 75

Fatal error: Uncaught Error: Call to a member function find() on boolean in Command line code:9
Stack trace:
#0 {main}
  thrown in Command line code on line 9
[2017-09-28 12:49:30][ERROR: input.scriptfilter] JSON error: JSON text did not start with array or object and option to allow fragments not set. in JSON:
Warning: file_get_contents(): stream does not support seeking in /Users/####/Desktop/Alfred/Alfred.alfredpreferences/workflows/user.workflow.####/simple_html_dom.php on line 75

Warning: file_get_contents(): Failed to seek to position -1 in the stream in /Users/####/Desktop/Alfred/Alfred.alfredpreferences/workflows/user.workflow.####/simple_html_dom.php on line 75

Fatal error: Uncaught Error: Call to a member function find() on boolean in Command line code:9
Stack trace:
#0 {main}
  thrown in Command line code on line 9
[2017-09-28 12:49:30][ERROR: input.scriptfilter] Code 255: Warning: file_get_contents(): stream does not support seeking in /Users/####/Desktop/Alfred/Alfred.alfredpreferences/workflows/user.workflow.####/simple_html_dom.php on line 75

Warning: file_get_contents(): Failed to seek to position -1 in the stream in /Users/####/Desktop/Alfred/Alfred.alfredpreferences/workflows/user.workflow.####/simple_html_dom.php on line 75

Fatal error: Uncaught Error: Call to a member function find() on boolean in Command line code:9
Stack trace:
#0 {main}
  thrown in Command line code on line 9
[2017-09-28 12:49:31][ERROR: input.scriptfilter] Code 255: Warning: file_get_contents(): stream does not support seeking in /Users/####/Desktop/Alfred/Alfred.alfredpreferences/workflows/user.workflow.####/simple_html_dom.php on line 75

Warning: file_get_contents(): Failed to seek to position -1 in the stream in /Users/####/Desktop/Alfred/Alfred.alfredpreferences/workflows/user.workflow.####/simple_html_dom.php on line 75

Fatal error: Uncaught Error: Call to a member function find() on boolean in Command line code:9
Stack trace:
#0 {main}
  thrown in Command line code on line 9

 

Link to comment

They say a player is clutch if he hits well when the game is on the line. For example, a hit is more valuable when the game is tied than when one team leads by several runs. The interesting thing about clutch is that numerous analytical studies have shown that clutch ability really does not exist. it's something we attribute to a player (like Yogi) based on smaller sample sizes. These studies have shown that a player who hits, let's say .300 overall, is probably going to hit about .300 when it matters. The problem with clutch is that the numbers can seem very real in a single season, but over larger samples they tend to even out. Anyway, that's much more than you asked, but that's the gist of it. A home run in a tie game would be a "clutch" hit since it would or could win the game. I try to avoid the term when possible. 

Link to comment

Thanks very much.

 

The statistical aspect is particularly interesting. 

 

I’d be interested to see a comparison with football (soccer).

 

In particular, Thierry Henry, one of the highest-scoring strikers ever only ever scored in one final (IIRC), and then only when he was left completely unmarked in front of goal, whereas Steven Gerrard, a midfielder, scored in lots of finals.

 

IMO, Gerrard was “clutch” (a “big game player” in footie terms), but Henry was a flat-track bully.

Link to comment

It could be that in soccer clutch skill does indeed exist. Also, I shouldn't be so dismissive of the skill in baseball. To expand even further, they have shown that the player that is most likely to be "clutch" by the average definition of clutch is someone who puts the ball in play a lot. That, though, doesn't really tie into clutch since how frequently a player hits the ball into play isn't related to the score, but rather that player's own skill set. Anyway, I wouldn't be surprised at all if it exists in soccer or might be a situation (I don't watch soccer so apologies if I butcher the terms) where one team is putting its best defender on a player (Henry) and not the other (Gerrard). That's one of the beautiful things about baseball. It's a series of events that are largely independent of what the team as a whole does. Batter vs. pitcher, ball in play vs. fielder, fielder vs. base runner and so on. That's what makes baseball so easy to quantify and it's why statisticians love it. There is so much data to dig into. There's very little that happens in baseball that's not individually achieved whereas in a sport like soccer I imagine you have players trying to create spacing for others (scorers) so all of that works together.

Link to comment
30 minutes ago, xilopaint said:

 

Two goals in a WC final match against Germany should count for something.

 

Not against that German side, tbh. That was the worst team the Germans have had in 50 years, and their only genuinely world-class player, Kahn, literally dropped the ball at Ronaldo's feet for the first goal.

Link to comment
33 minutes ago, deanishe said:

 

Not against that German side, tbh. That was the worst team the Germans have had in 50 years, and their only genuinely world-class player, Kahn, literally dropped the ball at Ronaldo's feet for the first goal.

 

True. Are you English, right? One of the greatest Ronaldo's performances I remember was against ManU in UCL when he was applauded in Old Trafford:

 

 

Unfortunately, that was not enough and Real Madrid ended up losing the match. I don't know why but I think the games of nowadays don't have those epic feelings.

 

Btw, what happens with the English team in World Cups? You guys seem to never display all your perceived potential.

Edited by xilopaint
Link to comment
1 minute ago, xilopaint said:

One of the greatest Ronaldo's performances I remember was against ManU in UCL when he was applauded in Old Trafford

 

That's actually the game I usually think of when I think of Ronaldo. I despise Man Utd. Ronaldo made me so very, very happy that day :) 

 

Credit where credit's due, mind. There aren't many fans who'd applaud an opposition player who'd destroyed them.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...