diff --git a/games.sql b/games.sql new file mode 100644 index 0000000..ce702ed --- /dev/null +++ b/games.sql @@ -0,0 +1,6 @@ +create table if not exists games ( + gamePk integer, + teamId text, + state text, + unique (teamId, gamePk) on conflict replace +); diff --git a/mlbgames.sh b/mlbgames.sh new file mode 100755 index 0000000..2a59deb --- /dev/null +++ b/mlbgames.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +set -e + +while getopts 'd:t:' opt +do + case $opt in + d) + db=$OPTARG + ;; + t) + team=$OPTARG + ;; + ?) + exit 1 + ;; + esac +done + +if [[ -z $db ]] +then + echo "$0:" '-d is required' >&2 + exit 1 +fi + +if [[ -z $team ]] +then + echo "$0:" '-t is required' >&2 + exit 1 +fi + +jqFilter='.dates[].games[] | "\(.gamePk),\(.status.detailedState)"' +fmt="OFS=\",\"; print \$1, \"$team\", \$2" +save="\"sqlite3 $db '.import --csv /dev/stdin games'\"" +mlblive schedule -t $team | jq -r "$jqFilter" | awk -F , "{$fmt | $save; close($save)}"