From a8f4bc5e3079e6762174221e15146fd196d949e3 Mon Sep 17 00:00:00 2001 From: filifa Date: Sun, 4 Aug 2024 00:13:13 -0500 Subject: [PATCH] add a column for posting begin/end of game --- mlbgames.sh | 2 +- schema.sql | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/mlbgames.sh b/mlbgames.sh index 2a59deb..c20927e 100755 --- a/mlbgames.sh +++ b/mlbgames.sh @@ -30,6 +30,6 @@ then fi jqFilter='.dates[].games[] | "\(.gamePk),\(.status.detailedState)"' -fmt="OFS=\",\"; print \$1, \"$team\", \$2" +fmt="OFS=\",\"; print \$1, \"$team\", \$2, 0" save="\"sqlite3 $db '.import --csv /dev/stdin games'\"" mlblive schedule -t $team | jq -r "$jqFilter" | awk -F , "{$fmt | $save; close($save)}" diff --git a/schema.sql b/schema.sql index 536ce33..f7a9d51 100644 --- a/schema.sql +++ b/schema.sql @@ -20,5 +20,15 @@ create table if not exists games ( gamePk integer, teamId text, state text, - unique (teamId, gamePk) on conflict replace + posted integer, + unique (teamId, gamePk) on conflict ignore ); + +create trigger if not exists delete_old_states +before insert on games +begin + delete from games + where gamePk = new.gamePk and + teamId = new.teamId and + state != new.state; +end;