Add notify bash wrapper script
This commit is contained in:
parent
26a5e66a05
commit
6e0d57a7dc
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,3 +1,8 @@
|
||||
|
||||
cache/
|
||||
|
||||
# python gitignore
|
||||
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[codz]
|
||||
|
||||
37
notify.sh
Executable file
37
notify.sh
Executable 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"
|
||||
Loading…
Reference in New Issue
Block a user