mlblive-mastodon-scripts/mlbhighlightsave.sh

42 lines
881 B
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
set -e
while getopts 'd:t:' opt
do
case $opt in
d)
db=$OPTARG
;;
t)
team=$OPTARG
;;
?)
exit 1
;;
esac
done
if [[ -z $db ]]
then
echo "$0:" '-d is required' >&2
exit 1
fi
if [[ -z $team ]]
then
echo "$0:" '-t is required' >&2
exit 1
fi
# grab most recently started live pk, if multiple
gamePk=$(mlblive schedule -t $team | jq '.dates[].games | map(select(.status.abstractGameState == "Live"))[-1].gamePk')
if [[ "$gamePk" = 'null' ]]
then
echo "$0:" 'no live games found' >&2
exit 1
fi
jqFilter='.highlights.highlights.items | map(select(.keywordsAll[].value == "highlight"))[] | {headline, id} + {url: (.playbacks | map(select(.name == "mp4Avc"))[0].url)}'
mlblive content -g $gamePk | jq -Sc --unbuffered "$jqFilter" | sed -u 's/$/0/' | split -l 1 --filter="sqlite3 $db '.mode ascii' '.separator ' '.import /dev/stdin mlbdata'"