mlblive-mastodon-scripts/highlights/mlbhighlightpost.sh

45 lines
913 B
Bash
Raw Normal View History

2024-07-27 02:42:09 +00:00
#!/bin/bash
set -e
2024-07-31 01:05:02 +00:00
while getopts 'd:a:' opt
2024-07-27 02:42:09 +00:00
do
case $opt in
d)
db=$OPTARG
;;
2024-07-31 01:05:02 +00:00
a)
account=$OPTARG
;;
2024-07-27 02:42:09 +00:00
?)
exit 1
;;
esac
done
if [[ -z $db ]]
then
echo "$0:" '-d is required' >&2
exit 1
fi
2024-07-31 01:05:02 +00:00
if [[ -z $account ]]
then
echo "$0:" '-a is required' >&2
exit 1
fi
2024-08-01 02:39:11 +00:00
# summary of what these variables do in the awk script:
2024-08-01 02:42:56 +00:00
# get: download the highlight from its url, and wait until it is downloaded
# before continuing
2024-08-01 02:39:11 +00:00
# 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
2024-07-31 01:05:02 +00:00
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}"