Add notify bash wrapper script

This commit is contained in:
Adrian Groh 2025-06-26 15:11:26 +02:00
parent 26a5e66a05
commit 6e0d57a7dc
Signed by: Gobidev
GPG Key ID: 3AA3153E98B0D771
2 changed files with 42 additions and 0 deletions

5
.gitignore vendored
View File

@ -1,3 +1,8 @@
cache/
# python gitignore
# Byte-compiled / optimized / DLL files # Byte-compiled / optimized / DLL files
__pycache__/ __pycache__/
*.py[codz] *.py[codz]

37
notify.sh Executable file
View File

@ -0,0 +1,37 @@
#!/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"