From 0342594993272e606500736b88712613971c1efe Mon Sep 17 00:00:00 2001 From: filifa Date: Fri, 26 Jul 2024 19:14:39 -0500 Subject: [PATCH] use flag for $db --- content.sh | 19 +++++++++++-------- postplays.sh | 18 +++++++++++++++--- subscribe.sh | 19 +++++++++++-------- 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/content.sh b/content.sh index 0cc424f..7f5cb29 100755 --- a/content.sh +++ b/content.sh @@ -2,9 +2,12 @@ set -e -while getopts 't:' opt +while getopts 'd:t:' opt do case $opt in + d) + db=$OPTARG + ;; t) team=$OPTARG ;; @@ -14,17 +17,17 @@ do esac done +if [[ -z $db ]] +then + echo "$0:" '-d is required' >&2 + exit 1 +fi + gamePk=$(./livepk.sh -t $team) if [[ -z $gamePk || "$gamePk" = 'null' ]] then exit 1 fi -if [[ -z $DB ]] -then - echo "$0:" '$DB not set' >&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/' | ./writedb.sh -d $DB -t highlights -c '' +mlblive content -g $gamePk | jq -Sc --unbuffered "$jqFilter" | sed -u 's/$/0/' | ./writedb.sh -d $db -t highlights -c '' diff --git a/postplays.sh b/postplays.sh index bc26b34..3523e9b 100755 --- a/postplays.sh +++ b/postplays.sh @@ -2,10 +2,22 @@ set -e -if [[ -z $DB ]] +while getopts 'd:' opt +do + case $opt in + d) + db=$OPTARG + ;; + ?) + exit 1 + ;; + esac +done + +if [[ -z $db ]] then - echo "$0:" '$DB not set' >&2 + echo "$0:" '-d is required' >&2 exit 1 fi -sqlite3 $DB < postplays.sql | awk -F  '{printf "%s\n\n%s %s\n#%s %s\n#%s %s\n\n#baseball #live\n", $1, $2, $3, $4, $5, $6, $7}' +sqlite3 $db < postplays.sql | awk -F  '{printf "%s\n\n%s %s\n#%s %s\n#%s %s\n\n#baseball #live\n", $1, $2, $3, $4, $5, $6, $7}' diff --git a/subscribe.sh b/subscribe.sh index 59e1b29..05d7634 100755 --- a/subscribe.sh +++ b/subscribe.sh @@ -2,9 +2,12 @@ set -e -while getopts 't:' opt +while getopts 'd:t:' opt do case $opt in + d) + db=$OPTARG + ;; t) team=$OPTARG ;; @@ -14,17 +17,17 @@ do esac done +if [[ -z $db ]] +then + echo "$0:" '-d is required' >&2 + exit 1 +fi + gamePk=$(./livepk.sh -t $team) if [[ -z $gamePk || "$gamePk" = 'null' ]] then exit 1 fi -if [[ -z $DB ]] -then - echo "$0:" '$DB not set' >&2 - 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/' | ./writedb.sh -d $DB -t playinfo -c '' +mlblive subscribe -g $gamePk | jq -Sc --unbuffered "$jqFilter" | sed -u 's/$/0/' | ./writedb.sh -d $db -t playinfo -c ''