mlblive-mastodon-scripts/highlights/mlbhighlightpost.sh

45 lines
913 B
Bash
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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}"