organize into folders

This commit is contained in:
filifa
2024-08-08 00:10:11 -05:00
parent 9ecc9a358b
commit 5197766815
11 changed files with 0 additions and 0 deletions

35
plays/mlbplaypost.sh Executable file
View File

@@ -0,0 +1,35 @@
#!/bin/bash
set -e
while getopts 'd:a:' opt
do
case $opt in
d)
db=$OPTARG
;;
a)
account=$OPTARG
;;
?)
exit 1
;;
esac
done
if [[ -z $db ]]
then
echo "$0:" '-d is required' >&2
exit 1
fi
if [[ -z $account ]]
then
echo "$0:" '-a is required' >&2
exit 1
fi
# format each row of data retreived from the select statement and pipe to toot
fmt='printf "%s\n\n%s %s\n#%s %s\n#%s %s\n\n#baseball #live\n", $1, $2, $3, $4, $5, $6, $7'
post="\"toot post --using $account\""
sqlite3 $db < postplays.sql | awk -F  "{$fmt | $post; close($post)}"

40
plays/mlbplaysave.sh Executable file
View File

@@ -0,0 +1,40 @@
#!/bin/bash
set -e
set -o pipefail
while getopts 'd:' opt
do
case $opt in
d)
db=$OPTARG
;;
?)
exit 1
;;
esac
done
if [[ -z $db ]]
then
echo "$0:" '-d is required' >&2
exit 1
fi
# grab the game pk of a single live game, if multiple (in case of spring
# training)
gamePk=$(sqlite3 $db "select gamePk from games where json ->> 'status' ->> 'detailedState' in ('In Progress', 'Warmup') limit 1")
if [[ -z "$gamePk" ]]
then
echo "$0:" 'no live games found' >&2
exit 1
fi
jqFilter='{gamePk} + (.gameData.teams | {awayTeam: .away.teamName, homeTeam: .home.teamName}) + (.liveData.plays.allPlays[] | (.result + (.about | {atBatIndex, halfInning, inning, isComplete, isScoringPlay, hasReview})))'
fmt='OFS=""; print $0, 0'
save="\"sqlite3 $db '.mode ascii' '.separator ' '.import /dev/stdin plays'\""
# grab select data from each response with jq, add 0 to the end of each line
# (to go in the 'posted' db column), then write each line as they come in to db
mlblive subscribe -g $gamePk | jq -Sc "$jqFilter" | awk "{$fmt | $save; close($save)}"

21
plays/postplays.sql Normal file
View File

@@ -0,0 +1,21 @@
.separator 
begin;
select
json ->> 'description',
json ->> 'halfInning',
json ->> 'inning',
json ->> 'awayTeam',
json ->> 'awayScore',
json ->> 'homeTeam',
json ->> 'homeScore'
from plays
where
json ->> 'description' is not null and
json ->> 'isScoringPlay' = 1 and
posted = 0;
update plays
set posted = 1
where posted = 0;
commit;