master
Bel LaPointe 2022-04-21 10:52:03 -06:00
parent 1d7fa28706
commit 510ded1bfa
1 changed files with 39 additions and 0 deletions

39
main.sh Executable file
View File

@ -0,0 +1,39 @@
#! /bin/sh
main() {
set -e
set -o pipefail
pull
}
pull() {
local last_f=/tmp/ntfy_to_alert.since
touch "$last_f"
local since="$(cat "$last_f" | grep . || echo $(($(date +%s)-60*60*4)))"
for line_b64 in $(
curl \
-sS \
-u "squeaky2x3:dYbtypGkHXFtq1E00k2H42SPGUowi" \
"https://ntfy.home.blapointe.com/alerts/json?since=$since&poll=1" \
| grep . \
| while read -r line; do
echo "$line" | base64
done
); do
local line="$(echo "$line_b64" | base64 --decode)"
local ts=$(echo "$line" | jq -r .time)
if ((ts+1>since)); then
since=$((ts+1))
fi
if which say &> /dev/null; then
say "$(echo "$line" | jq -r '.title+" "+.message')"
else
echo "!!! $line"
fi
done
echo "$since" | tee "$last_f" >&2
}
if [ "$0" == "$BASH_SOURCE" ]; then
main "$@"
fi