mlbstats/README.md

54 lines
2.3 KiB
Markdown
Raw Permalink Normal View History

2025-05-10 17:29:38 +00:00
# mlbstats
mlbstats is a CLI tool for retrieving data from Major League Baseball's Stats
2024-07-28 19:10:40 +00:00
API, including efficient retrieval of live game data. Unofficial documentation
on the Stats API can be found
[here](https://github.com/toddrob99/MLB-StatsAPI/wiki/Endpoints) (thanks to
GitHub user toddrob99 for this resource).
## Usage
2025-05-10 17:29:38 +00:00
mlbstats provides sub-commands to query a subset of the Stats API endpoints. As
2024-07-28 19:10:40 +00:00
of the time of writing, the sub-commands are:
2025-05-10 17:29:38 +00:00
* `mlbstats content` (accesses the `game_content` endpoint)
* `mlbstats feed` (accesses the `game` endpoint)
* `mlbstats schedule` (accesses the `schedule` endpoint)
* `mlbstats standings` (accesses the `standings` endpoint)
* `mlbstats subscribe` (accesses the game WebSocket endpoint)
2024-07-28 19:10:40 +00:00
Each sub-command outputs the raw JSON response from the API. This can then be
piped into other commands like `jq` for further processing. See [this
2025-05-10 17:29:38 +00:00
repo](https://scm.dairydemon.net/filifa/mlbstats-mastodon-scripts) for examples
of how the author uses this program for posting live score updates and
2024-07-28 19:10:40 +00:00
highlights to Mastodon.
2025-05-10 17:29:38 +00:00
Note that mlbstats does not provide sub-commands for every endpoint, or flags
2024-07-28 19:10:40 +00:00
for every parameter of every endpoint. The functionality provided was
prioritized based on the author's own needs. However, the author has made every
effort to make the current functionality's code easy to read, and hopes it will
2024-07-29 03:27:05 +00:00
be similarly easy for other developers to extend functionality as needed.
2024-07-28 19:10:40 +00:00
### subscribe sub-command
2025-05-10 17:29:38 +00:00
`mlbstats subscribe` provides an efficient way to obtain live data on active MLB
games. Supply the game's PK (which can be retrieved with `mlbstats schedule`) to
2024-07-29 02:45:13 +00:00
receive updates as they happen, without needing to blindly query the `game`
endpoint.
2024-07-28 19:10:40 +00:00
2024-07-29 02:46:06 +00:00
### Example
2025-05-10 17:29:38 +00:00
Use `mlbstats schedule` to get the game PK(s) for today's Reds game:
2024-07-29 02:46:06 +00:00
```
2025-05-10 17:29:38 +00:00
mlbstats schedule -t cin
2024-07-29 02:46:06 +00:00
```
Optionally, use `jq` to filter this output to *just* the game PK(s):
```
2025-05-10 17:29:38 +00:00
mlbstats schedule -t cin | jq '.dates[].games[].gamePk'
2024-07-29 02:46:06 +00:00
```
Then, pass a PK to get live updates:
```
2025-05-10 17:29:38 +00:00
mlbstats subscribe -g <gamePk>
2024-07-29 02:46:06 +00:00
```
2024-07-28 19:10:40 +00:00
## Disclaimer
This program and its author are not affiliated with MLB. Content supplied by
2025-04-08 04:58:12 +00:00
MLB's Stats API is copyright MLB Advanced Media, L.P., and use of any content
provided by the API acknowledges agreement to the terms posted [here](
2024-07-28 19:10:40 +00:00
http://gdx.mlb.com/components/copyright.txt).