From 6f1ae79122a9445d922954fdf5ca8b481a33a11b Mon Sep 17 00:00:00 2001 From: meftimes Date: Sun, 3 Nov 2024 20:24:16 -0500 Subject: [PATCH] professional rework --- remind.sh | 83 +++++++++++++++++++++++++++---------------------------- 1 file changed, 41 insertions(+), 42 deletions(-) diff --git a/remind.sh b/remind.sh index 67f8376..45b00f1 100755 --- a/remind.sh +++ b/remind.sh @@ -1,49 +1,48 @@ #!/bin/bash -TODAY=$(date +"%B %d") #month day -CURRENTYEAR=$(date +%Y) +DATES_FILE="/home/meftimes/scripts/dates.txt" +NTFY_TOKEN="token_goes_here" -if grep -q "$TODAY" /home/$USER/scripts/dates.txt; then - NAME=$(grep "$TODAY" /home/meftimes/scripts/dates.txt | awk '{$1=$2=$3=$4=""; print $0}') - BIRTHYEAR=$(grep "$TODAY" /home/meftimes/scripts/dates.txt | awk '{print $4}') - AGE=$(expr $CURRENTYEAR - $BIRTHYEAR) - CATEGORY=$(grep "$TODAY" /home/meftimes/scripts/dates.txt | awk '{print $1}') - REMINDER=$(grep "$TODAY" /home/meftimes/scripts/dates.txt | awk '{$1=$2=$3=""; print $0}') +TODAY=$(date +"%B %d") #works - case $CATEGORY in - "BIRTHDAY" ) - curl \ - -u :ntfy_token_goes_here \ - -H "Priority: urgent" \ - -H "Tags: birthday" \ - -H "Title: Birthday" \ - -d "$NAME is $AGE years old today!" \ - https://ntfy_url_goes_here - ;; + grep "$TODAY" $DATES_FILE | while read -r LINE; do + CATEGORY=$(echo "$LINE" | awk '{print $1}') + + case $CATEGORY in + "BIRTHDAY" ) + CURRENTYEAR=$(date +%Y) + NAME=$(echo "$LINE" | awk '{$1=$2=$3=$4=""; print $0}' ) + BIRTHYEAR=$(echo "$LINE" | awk '{print $4}') + AGE=$(( CURRENTYEAR - BIRTHYEAR )) - "RENT" ) - curl \ - -u :ntfy_token_goes_here \ - -H "Priority: urgent" \ - -H "Tags: money_with_wings" \ - -H "Title: Rent Reminder" \ - -d "Payment due!" \ - https://ntfy_url_goes_here - ;; + TAGS="birthday" + TITLE="Birthday" + CONTENT="$NAME is $AGE years old today!" + ;; - "REMINDER" ) - curl \ - -u :ntfy_token_goes_here \ - -H "Priority: urgent" \ - -H "Tags: reminder_ribbon" \ - -H "Title: Reminder" \ - -d "$REMINDER" \ - https://ntfy_url_goes_here - ;; - esac + "RENT" ) + TAGS="money_with_wings" + TITLE="Rent Reminder" + CONTENT="Payment due!" + ;; -else - echo true #do nothing -fi - -#absolute path required in script for cronjob to work + "REMINDER" ) + REMINDER=$(echo "$LINE" | awk '{$1=$2=$3=""; print $0}') + TAGS="reminder_ribbon" + TITLE="Reminder" + CONTENT="$REMINDER" + ;; + *) + TAGS="" + TITLE="Unknown category" + CONTENT="..." + esac + + curl \ + -u :$NTFY_TOKEN \ + -H "Priority: urgent" \ + -H "Tags: $TAGS" \ + -H "Title: $TITLE" \ + -d "$CONTENT" \ + https://ntfy.meftimes.com/alerts + done