From e873ed44b8d1649ac3eae131e2193ac59bbaab04 Mon Sep 17 00:00:00 2001 From: filifa Date: Wed, 31 Jul 2024 20:04:31 -0500 Subject: [PATCH] only make and use one table --- mlbhighlightsave.sh | 2 +- mlbplaysave.sh | 2 +- posthighlights.sql | 4 ++-- postplays.sql | 4 ++-- schema.sql | 15 +++------------ 5 files changed, 9 insertions(+), 18 deletions(-) diff --git a/mlbhighlightsave.sh b/mlbhighlightsave.sh index f64ebe1..2bfdf3a 100755 --- a/mlbhighlightsave.sh +++ b/mlbhighlightsave.sh @@ -37,4 +37,4 @@ then 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 mlbdata -c '' diff --git a/mlbplaysave.sh b/mlbplaysave.sh index 9192a4f..4ca2eda 100755 --- a/mlbplaysave.sh +++ b/mlbplaysave.sh @@ -37,4 +37,4 @@ then 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 plays -c '' +mlblive subscribe -g $gamePk | jq -Sc --unbuffered "$jqFilter" | sed -u 's/$/0/' | writedb.sh -d $db -t mlbdata -c '' diff --git a/posthighlights.sql b/posthighlights.sql index f095401..c8c434a 100644 --- a/posthighlights.sql +++ b/posthighlights.sql @@ -5,12 +5,12 @@ select json ->> 'headline', json ->> 'id', json ->> 'url' -from highlights +from mlbdata where json ->> 'url' is not null and posted = 0; -update highlights +update mlbdata set posted = 1 where posted = 0; commit; diff --git a/postplays.sql b/postplays.sql index 7222670..2a3cc05 100644 --- a/postplays.sql +++ b/postplays.sql @@ -9,13 +9,13 @@ json ->> 'awayTeam', json ->> 'awayScore', json ->> 'homeTeam', json ->> 'homeScore' -from plays +from mlbdata where json ->> 'description' is not null and json ->> 'isScoringPlay' = 1 and posted = 0; -update plays +update mlbdata set posted = 1 where posted = 0; commit; diff --git a/schema.sql b/schema.sql index 08e7c02..0650dad 100644 --- a/schema.sql +++ b/schema.sql @@ -1,17 +1,8 @@ -create table if not exists plays ( +create table if not exists mlbdata ( "json" text unique on conflict ignore, "posted" integer check ("posted" in (0, 1)) ); -create index if not exists nonposted_plays -on plays(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) +create index if not exists nonposted +on mlbdata(posted) where posted = 0;