ausweisstatus/notify.sh

38 lines
961 B
Bash
Executable File

#!/usr/bin/env bash
# This script runs ausweisstatus.py with the provided arguments sends a notification to a discord webhook if the
# status has changed since the last execution
# Usage: ./notify.sh <P|R|ID> <Seriennummer> <Geburtsdatum>
WEBHOOK_URL=""
notify() {
message="New status for $2 ($3): $1"
echo "$message"
curl -q -i -H "Accept: application/json" -H "Content-Type:application/json" -X POST --data "{\"content\": \"$message\"}" "$WEBHOOK_URL" &>/dev/null
}
# source venv if found
test -e venv/bin/activate && source venv/bin/activate
test -e .venv/bin/activate && source .venv/bin/activate
output="$(./ausweisstatus.py "$@")"
if [ $? != 0 ]; then
echo "$output"
exit 1
fi
if [[ -e ./cache/"$2" ]]; then
read -r previous < ./cache/"$2"
if [ "$previous" != "$output" ]; then
notify "$output" "$2" "$1"
else
echo "No status change for $2"
fi
fi
mkdir -p ./cache
echo "$output" > ./cache/"$2"