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

44
highlights/mlbhighlightpost.sh Executable file
View File

@@ -0,0 +1,44 @@
#!/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
# summary of what these variables do in the awk script:
# get: download the highlight from its url, and wait until it is downloaded
# before continuing
# fmt: print the text of the post
# post: use toot to post the text and the downloaded highlight (also wait until
# the toot is posted before continuing)
# rm: delete the downloaded highlight
get='print $3 | "xargs curl >" $2; close("xargs curl >" $2)'
fmt='printf "%s\n\n#baseball #highlights\n", $1'
post='"toot post -m " $2'
post+="\" --using $account\""
del='print $2 | "xargs rm"'
sqlite3 $db < posthighlights.sql | awk -F  "{$get; $fmt | $post; close($post); $del}"

36
highlights/mlbhighlightsave.sh Executable file
View File

@@ -0,0 +1,36 @@
#!/bin/bash
set -e
set -o pipefail
while getopts 'd:t:' 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', 'Game Over') limit 1")
if [[ -z "$gamePk" ]]
then
echo "$0:" 'no live games found' >&2
exit 1
fi
# grab select data from response with jq, add 0 to the end of each line (to go
# in the 'posted' db column), then write each line to db
jqFilter='.highlights.highlights.items | map(select(.keywordsAll[].value == "highlight"))[] | {headline, id} + {url: (.playbacks | map(select(.name == "mp4Avc"))[0].url)} | select(.url | startswith("https://mlb-cuts-diamond"))'
mlblive content -g $gamePk | jq -Sc "$jqFilter" | sed 's/$/0/' | sqlite3 $db '.mode ascii' '.separator  \n' '.import /dev/stdin highlights'

View File

@@ -0,0 +1,16 @@
.separator 
begin;
select
json ->> 'headline',
json ->> 'id',
json ->> 'url'
from highlights
where
json ->> 'url' is not null and
posted = 0;
update highlights
set posted = 1
where posted = 0;
commit;