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;