From 6f25185b924145fc79b3696feeecc39fc665c105 Mon Sep 17 00:00:00 2001 From: filifa Date: Wed, 24 Jul 2024 21:17:36 -0500 Subject: [PATCH] initial commit --- content.sh | 10 ++++++++++ livepk.sh | 4 ++++ postplays.sh | 3 +++ postplays.sql | 19 +++++++++++++++++++ schema.sql | 17 +++++++++++++++++ subscribe.sh | 10 ++++++++++ 6 files changed, 63 insertions(+) create mode 100755 content.sh create mode 100755 livepk.sh create mode 100755 postplays.sh create mode 100644 postplays.sql create mode 100644 schema.sql create mode 100755 subscribe.sh diff --git a/content.sh b/content.sh new file mode 100755 index 0000000..5cd0d62 --- /dev/null +++ b/content.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +gamePk=$(./livepk.sh) +if [[ "$gamePk" = 'null' ]] +then + 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 highlights'" diff --git a/livepk.sh b/livepk.sh new file mode 100755 index 0000000..ee9fc0d --- /dev/null +++ b/livepk.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# grab most recently started live pk, if multiple +echo $(mlblive schedule -t $TEAM | jq '.dates[].games | map(select(.status.abstractGameState == "Live"))[-1].gamePk') diff --git a/postplays.sh b/postplays.sh new file mode 100755 index 0000000..d67910c --- /dev/null +++ b/postplays.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +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/postplays.sql b/postplays.sql new file mode 100644 index 0000000..4b72e93 --- /dev/null +++ b/postplays.sql @@ -0,0 +1,19 @@ +.separator  + +begin; +select +json ->> 'description', +json ->> 'halfInning', +json ->> 'inning', +json ->> 'awayTeam', +json ->> 'awayScore', +json ->> 'homeTeam', +json ->> 'homeScore' +from playinfo +where +json ->> 'description' is not null and +json ->> 'isScoringPlay' = 1 and +posted = 0; + +-- update posted here +commit; diff --git a/schema.sql b/schema.sql new file mode 100644 index 0000000..c3501c6 --- /dev/null +++ b/schema.sql @@ -0,0 +1,17 @@ +create table if not exists playinfo ( + "json" text unique on conflict ignore, + "posted" integer check ("posted" in (0, 1)) +); + +create index if not exists nonposted_playinfo +on playinfo(posted) +where posted = 0; + +create table if not exists highlights ( + "json" text unique on conflict ignore, + "posted" integer check ("posted" in (0, 1)) +); + +create index if not exists nonposted_highlights +on highlights(posted) +where posted = 0; diff --git a/subscribe.sh b/subscribe.sh new file mode 100755 index 0000000..5370cee --- /dev/null +++ b/subscribe.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +gamePk=$(./livepk.sh) +if [[ "$gamePk" = 'null' ]] +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})))' +mlblive subscribe -g $gamePk | jq -Sc --unbuffered "$jqFilter" | sed -u 's/$/0/' | split -l 1 --filter="sqlite3 $DB '.mode ascii' '.separator ' '.import /dev/stdin playinfo'"