2024-07-25 02:17:36 +00:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
2024-07-26 03:34:35 +00:00
|
|
|
|
set -e
|
2024-08-02 01:04:58 +00:00
|
|
|
|
set -o pipefail
|
2024-07-26 03:34:35 +00:00
|
|
|
|
|
2024-07-27 00:14:39 +00:00
|
|
|
|
while getopts 'd:t:' opt
|
2024-07-26 03:27:25 +00:00
|
|
|
|
do
|
|
|
|
|
case $opt in
|
2024-07-27 00:14:39 +00:00
|
|
|
|
d)
|
|
|
|
|
db=$OPTARG
|
|
|
|
|
;;
|
2024-07-26 03:27:25 +00:00
|
|
|
|
?)
|
|
|
|
|
exit 1
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
2024-07-27 00:14:39 +00:00
|
|
|
|
if [[ -z $db ]]
|
2024-07-25 02:17:36 +00:00
|
|
|
|
then
|
2024-07-27 00:14:39 +00:00
|
|
|
|
echo "$0:" '-d is required' >&2
|
2024-07-25 02:17:36 +00:00
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2024-08-03 20:54:35 +00:00
|
|
|
|
# grab the game pk of a single live game, if multiple (in case of spring
|
|
|
|
|
# training)
|
2024-08-09 03:17:11 +00:00
|
|
|
|
gamePk=$(sqlite3 $db "select json ->> 'gamePk' from games where json ->> 'status' ->> 'detailedState' in ('In Progress', 'Game Over') limit 1")
|
2024-08-03 20:54:35 +00:00
|
|
|
|
if [[ -z "$gamePk" ]]
|
2024-07-26 03:48:57 +00:00
|
|
|
|
then
|
2024-07-31 02:36:11 +00:00
|
|
|
|
echo "$0:" 'no live games found' >&2
|
2024-07-26 03:48:57 +00:00
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2024-08-01 02:39:11 +00:00
|
|
|
|
# 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
|
2024-08-02 01:42:12 +00:00
|
|
|
|
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"))'
|
2024-08-03 22:35:08 +00:00
|
|
|
|
mlblive content -g $gamePk | jq -Sc "$jqFilter" | sed 's/$/0/' | sqlite3 $db '.mode ascii' '.separator \n' '.import /dev/stdin highlights'
|