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

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\"}"
