mlblive-mastodon-scripts/subscribe.sh

31 lines
619 B
Bash
Raw Normal View History

2024-07-25 02:17:36 +00:00
#!/bin/bash
2024-07-26 03:34:35 +00:00
set -e
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
2024-07-26 03:48:57 +00:00
if [[ -z $DB ]]
then
echo "$0:" '$DB not set' >&2
exit 1
fi
2024-07-25 02:17:36 +00:00
jqFilter='{gamePk} + (.gameData.teams | {awayTeam: .away.teamName, homeTeam: .home.teamName}) + (.liveData.plays.allPlays[] | (.result + (.about | {atBatIndex, halfInning, inning, isComplete, isScoringPlay, hasReview})))'
2024-07-27 00:02:45 +00:00
mlblive subscribe -g $gamePk | jq -Sc --unbuffered "$jqFilter" | sed -u 's/$/0/' | ./writedb.sh -d $DB -t playinfo -c ''