initial commit

This commit is contained in:
filifa 2024-07-24 21:17:36 -05:00
commit 6f25185b92
6 changed files with 63 additions and 0 deletions

10
content.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/bash
gamePk=$(./livepk.sh)
if [[ "$gamePk" = 'null' ]]
then
exit 1
fi
jqFilter='.highlights.highlights.items | map(select(.keywordsAll[].value == "highlight"))[] | {headline, id} + {url: (.playbacks | map(select(.name == "mp4Avc"))[0].url)}'
mlblive content -g $gamePk | jq -Sc --unbuffered "$jqFilter" | sed -u 's/$/0/' | split -l 1 --filter="sqlite3 $DB '.mode ascii' '.separator ' '.import /dev/stdin highlights'"

4
livepk.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
# grab most recently started live pk, if multiple
echo $(mlblive schedule -t $TEAM | jq '.dates[].games | map(select(.status.abstractGameState == "Live"))[-1].gamePk')

3
postplays.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
sqlite3 $DB < postplays.sql | awk -F  '{printf "%s\n\n%s %s\n#%s %s\n#%s %s\n\n#baseball #live\n", $1, $2, $3, $4, $5, $6, $7}'

19
postplays.sql Normal file
View File

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

17
schema.sql Normal file
View File

@ -0,0 +1,17 @@
create table if not exists playinfo (
"json" text unique on conflict ignore,
"posted" integer check ("posted" in (0, 1))
);
create index if not exists nonposted_playinfo
on playinfo(posted)
where posted = 0;
create table if not exists highlights (
"json" text unique on conflict ignore,
"posted" integer check ("posted" in (0, 1))
);
create index if not exists nonposted_highlights
on highlights(posted)
where posted = 0;

10
subscribe.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/bash
gamePk=$(./livepk.sh)
if [[ "$gamePk" = 'null' ]]
then
exit 1
fi
jqFilter='{gamePk} + (.gameData.teams | {awayTeam: .away.teamName, homeTeam: .home.teamName}) + (.liveData.plays.allPlays[] | (.result + (.about | {atBatIndex, halfInning, inning, isComplete, isScoringPlay, hasReview})))'
mlblive subscribe -g $gamePk | jq -Sc --unbuffered "$jqFilter" | sed -u 's/$/0/' | split -l 1 --filter="sqlite3 $DB '.mode ascii' '.separator ' '.import /dev/stdin playinfo'"