From e22bf6a6eb05c4ae92d0def26a18bbd281fde75d Mon Sep 17 00:00:00 2001 From: filifa Date: Fri, 2 Aug 2024 22:00:42 -0500 Subject: [PATCH] use awk to handle locking problem --- mlbplaysave.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mlbplaysave.sh b/mlbplaysave.sh index 029d8fd..e963faf 100755 --- a/mlbplaysave.sh +++ b/mlbplaysave.sh @@ -38,7 +38,11 @@ then exit 1 fi +jqFilter='{gamePk} + (.gameData.teams | {awayTeam: .away.teamName, homeTeam: .home.teamName}) + (.liveData.plays.allPlays[] | (.result + (.about | {atBatIndex, halfInning, inning, isComplete, isScoringPlay, hasReview})))' + +fmt='OFS=""; print $0, 0' +save="\"sqlite3 $db '.mode ascii' '.separator ' '.import /dev/stdin mlbdata'\"" + # grab select data from each response with jq, add 0 to the end of each line # (to go in the 'posted' db column), then write each line as they come in to db -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/' | split -l 1 --filter="sqlite3 $db '.mode ascii' '.separator ' '.import /dev/stdin mlbdata'" +mlblive subscribe -g $gamePk | jq -Sc --unbuffered "$jqFilter" | awk "{$fmt | $save; close($save)}"