mlblive-mastodon-scripts/subscribe.sh

23 lines
602 B
Bash
Raw Normal View History

2024-07-25 02:17:36 +00:00
#!/bin/bash
2024-07-26 03:27:25 +00:00
while getopts 't:' opt
do
case $opt in
t)
team=$OPTARG
;;
?)
exit 1
;;
esac
done
gamePk=$(./livepk.sh -t $team)
if [[ -z $gamePk || "$gamePk" = 'null' ]]
2024-07-25 02:17:36 +00:00
then
exit 1
fi
jqFilter='{gamePk} + (.gameData.teams | {awayTeam: .away.teamName, homeTeam: .home.teamName}) + (.liveData.plays.allPlays[] | (.result + (.about | {atBatIndex, halfInning, inning, isComplete, isScoringPlay, hasReview})))'
mlblive subscribe -g $gamePk | jq -Sc --unbuffered "$jqFilter" | sed -u 's/$/0/' | split -l 1 --filter="sqlite3 $DB '.mode ascii' '.separator ' '.import /dev/stdin playinfo'"