39 lines
1.0 KiB
Bash
Executable File
39 lines
1.0 KiB
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>
|
|
# also set WEBHOOK_URL env var
|
|
|
|
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
|
|
else
|
|
echo "No previous state found, caching current status for $2"
|
|
fi
|
|
|
|
mkdir -p ./cache
|
|
echo "$output" > ./cache/"$2"
|