From 6e0d57a7dc41372ea445f2cd6d67439ed04ba9b4 Mon Sep 17 00:00:00 2001 From: Adrian Groh Date: Thu, 26 Jun 2025 15:11:26 +0200 Subject: [PATCH] Add notify bash wrapper script --- .gitignore | 5 +++++ notify.sh | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100755 notify.sh diff --git a/.gitignore b/.gitignore index b7faf40..4843343 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ + +cache/ + +# python gitignore + # Byte-compiled / optimized / DLL files __pycache__/ *.py[codz] diff --git a/notify.sh b/notify.sh new file mode 100755 index 0000000..95d8d87 --- /dev/null +++ b/notify.sh @@ -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 + +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"