46 lines
1.0 KiB
Bash
Executable File
46 lines
1.0 KiB
Bash
Executable File
#!/bin/bash
|
||
|
||
set -e
|
||
set -o pipefail
|
||
|
||
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 the game pk of a single live game, if multiple (in case of spring
|
||
# training)
|
||
gamePk=$(sqlite3 $db "select gamePk from games where teamId='$team' and state='In Progress' limit 1")
|
||
if [[ -z "$gamePk" ]]
|
||
then
|
||
echo "$0:" 'no live games found' >&2
|
||
exit 1
|
||
fi
|
||
|
||
# grab select data from response with jq, add 0 to the end of each line (to go
|
||
# in the 'posted' db column), then write each line to db
|
||
jqFilter='.highlights.highlights.items | map(select(.keywordsAll[].value == "highlight"))[] | {headline, id} + {url: (.playbacks | map(select(.name == "mp4Avc"))[0].url)} | select(.url | startswith("https://mlb-cuts-diamond"))'
|
||
mlblive content -g $gamePk | jq -Sc "$jqFilter" | sed 's/$/0/' | sqlite3 $db '.mode ascii' '.separator \n' '.import /dev/stdin mlbdata'
|