Scripts for posting MLB content to Mastodon
Go to file
filifa c85c101b59 also check on game over 2024-08-07 23:09:30 -05:00
LICENSE add license 2024-07-28 12:46:10 -05:00
README.md add info about play scripts 2024-08-06 19:31:05 -05:00
mlbfinalpost.sh fix sql file 2024-08-04 15:56:07 -05:00
mlbgames.sh remove team arg 2024-08-05 23:26:57 -05:00
mlbhighlightpost.sh add comments 2024-07-31 21:48:16 -05:00
mlbhighlightsave.sh also check on game over 2024-08-07 23:09:30 -05:00
mlbplaypost.sh close pipe after every post 2024-08-01 18:29:44 -05:00
mlbplaysave.sh remove team arg 2024-08-05 23:26:57 -05:00
mlbstartpost.sh add scripts for start and end of games 2024-08-04 15:31:07 -05:00
postfinal.sql remove state column 2024-08-04 16:00:48 -05:00
posthighlights.sql update table names 2024-08-03 17:35:08 -05:00
postplays.sql update table names 2024-08-03 17:35:08 -05:00
poststart.sql remove state column 2024-08-04 16:00:48 -05:00
schema.sql remove team arg 2024-08-05 23:26:57 -05:00

README.md

mlblive-mastodon-scripts

This repo contains some scripts to help automate posting live MLB game updates to Mastodon.

Structure

  • mlbplaysave.sh and mlbplaypost.sh are 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.sh and mlbhighlightpost.sh work similarly to the previous pair, but post video highlights instead.
  • mlbgames.sh, mlbstartpost.sh, and mlbfinalpost.sh are used to make a post at the start and end of games.
  • posthighlights.sql, postplays.sql, poststart.sql, and postfinal.sql are used by the posting scripts to select unposted data and then mark that data as posted.
  • schema.sql defines 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:

  • mlblive, another program I wrote for retrieving data from MLB's Stats API
  • toot, a CLI program for Mastodon
  • jq, a program for processing JSON data
  • sqlite3 for 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:

  1. Put all the shell scripts somewhere convenient (I put them in ~/.local/bin).
  2. Pick a directory to keep the SQLite database in (I picked ~/.local/share/mlblive).
  3. Create the database with sqlite3 <filename> < schema.sql
    • I recommend making at least one database for each bot account you plan to set up.
  4. Put the other SQL scripts in the same directory as the database.
  5. Review the scripts to see what arguments they require.
  6. 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.