|
|
||
|---|---|---|
| games | ||
| highlights | ||
| plays | ||
| LICENSE | ||
| README.md | ||
| schema.sql | ||
README.md
mlbstats-mastodon-scripts
This repo contains some scripts to help automate posting live MLB game updates to Mastodon.
Structure
mlbgames.sh,mlbstartpost.sh, andmlbfinalpost.share used to make a post at the start and end of games.mlbgames.shpopulates thegamestable of a SQLite database, which the play and highlight scripts read when running, so you'll need to runmlbgames.shif you want to use the other scripts.mlbplaysave.shandmlbplaypost.share used in tandem to post scoring updates. The former saves new plays to a SQLite database, and the latter reads the database and posts any scoring plays that have not been posted yet.mlbhighlightsave.shandmlbhighlightpost.shwork similarly to the previous pair, but post video highlights instead.posthighlights.sql,postplays.sql,poststart.sql, andpostfinal.sqlare used by the posting scripts to select unposted data and then mark that data as posted.schema.sqldefines the table that new data gets saved to.
Note that there are invisible characters (like 0x1f) in some of the files.
These are used as delimiters when processing the data.
How to use
Dependencies
To run these scripts, you'll need a few other programs:
- mlbstats, another program I wrote for retrieving data from MLB's Stats API
toot, a CLI program for Mastodonjq, a program for processing JSON datasqlite3for saving and loading data- some standard Unix programs (
sed,awk,curl, etc.)
You may want to review the scripts yourself to see what you might be missing.
Setup guidelines
Here's some high-level instructions to mirror the setup I use for these scripts:
- Put all the shell scripts somewhere convenient (I put them in
~/.local/bin). - Pick a directory to keep the SQLite database in (I picked
~/.local/share/mlbstats). - Create the database with
sqlite3 <filename> < schema.sql- I recommend making one database for plays and one for highlights (assuming you wish to process both) for each team you want to follow. Separate databases for plays and highlights will reduce delays due to locking.
- Put the other SQL scripts in the same directory as the database.
- Review the shell scripts to see what arguments they require.
- Write some systemd services and timers to execute the shell scripts
automatically on some interval. Set the working directory to the directory
with the database.
- I have
mlbsaveplays.shrunning as a simple service, and all the other scripts (games, highlights,mlbpostplays.sh) running as oneshot services that execute on timers.
- I have