create new script and schema for keeping track of game status
This commit is contained in:
parent
8f051bf050
commit
2c11488dc2
|
@ -0,0 +1,6 @@
|
|||
create table if not exists games (
|
||||
gamePk integer,
|
||||
teamId text,
|
||||
state text,
|
||||
unique (teamId, gamePk) on conflict replace
|
||||
);
|
|
@ -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)}"
|
Loading…
Reference in New Issue