Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Get Park Factors Leaderboard data from baseballsavant.mlb.com
- *
- * @param {2022} year The year filter.
- * @param {true} headers Return the headers.
- * @return {array} Park Factors Leaderboard data.
- * @customfunction
- */
- function BBSAVANT(year = 2022, headers = true) {
- const url = `https://baseballsavant.mlb.com/leaderboard/statcast-park-factors?type=year&year=${year}&batSide=&stat=index_wOBA&condition=All`
- const request = UrlFetchApp.fetch(url)
- const html = request.getContentText()
- let data
- console.log(html)
- try {
- const json = /var data = (.*?);/gmsi.exec(html)
- console.log(json)
- data = JSON.parse(json[1])
- } catch (e) {
- throw new Error("Error getting data")
- }
- const results = [];
- data.forEach((row, i) => {
- if (i === 0 && headers) {
- results.push(Object.keys(row))
- }
- results.push(Object.values(row))
- })
- return results
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement