Skip to content

Commit

Permalink
Add an expirydays config option to warn about balance expiration
Browse files Browse the repository at this point in the history
If the balance is about to expire, warn about it even if the amount of
the balance is still sufficient.
  • Loading branch information
dfandrich committed Sep 5, 2023
1 parent 1d0348e commit d879f6f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ be available in the PATH:
* [bash](https://www.gnu.org/software/bash/bash.html)
* [curl-impersonate](https://github.com/lwthiker/curl-impersonate), **or**
* [Docker](https://www.docker.com/)
* [gawk](https://www.gnu.org/software/gawk/gawk.html) (gawk)
* [HTML Tidy](https://www.html-tidy.org/) (tidy)
* [XMLStarlet](https://xmlstar.sourceforge.net/) (xmlstarlet)
* a sendmail-compatible MTA (sendmail)
Expand Down Expand Up @@ -48,8 +49,12 @@ Set `warnlimit` to the dollar amount below which an warning e-mail will be
sent when the script is run. `lowmail` must be set to `yes` for an e-mail to
actually be sent.

Set `expirydays` to the number of days before expiry of the balance after which a
warning e-mail will be sent. This defaults to 7. `lowmail` must be set to `yes`
for an e-mail to actually be sent.

Set `lowmail` to `yes` to have the script send an e-mail whenever the balance
goes below `warnlimit`.
goes below `warnlimit` or the expiry date is within `expirydays`.

Set `alwaysmail` to `yes` to have the script send an e-mail every time it is
run, regardless of the limit. Leave it blank to only mail below the warning
Expand Down
17 changes: 16 additions & 1 deletion speakout-account-info
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ account=
password=
recipient=
warnlimit=0
expirydays=7
alwaysmail=
lowmail=
quiet=
Expand Down Expand Up @@ -147,9 +148,23 @@ As of $(date), the balance remaining on the cellular number $NICEPHONENUM is
<span style='font-size: medium'>\$$BALANCE</span> which expires $EXPIRY.
EOF

if awk -F/ -v EXPIRYDAYS="$expirydays" '{exit mktime($3 " " $1 " " $2 " 00 00 00") - systime() >= EXPIRYDAYS * 24*3600}' <<< "$EXPIRY"; then
readonly TIMEEXCEEDED=yes
cat >>"$CONTENTFILE" <<EOF
<span style='color: pink; font-weight: bold;'>This is expiring within $expirydays days!</span>
EOF
else
readonly TIMEEXCEEDED=
fi

if [[ -n "$LIMITEXCEEDED" ]]; then
cat >>"$CONTENTFILE" <<EOF
<span style='color: pink; font-weight: bold;'>This is below the warning threshold of \$$warnlimit!</span>
EOF
fi

if [[ -n "$LIMITEXCEEDED" || -n "$TIMEEXCEEDED" ]]; then
cat >>"$CONTENTFILE" <<EOF
<p>
Add more money to your account now by
<a href="https://www.speakout7eleven.ca/userinfo/activation/topup/an/$PHONENUM/">choosing an amount here</a>.
Expand All @@ -162,7 +177,7 @@ cat >>"$CONTENTFILE" <<EOF
</body></html>
EOF

if [[ -n "$recipient" && ( -n "$alwaysmail" || ( -n "$lowmail" && -n "$LIMITEXCEEDED" ) ) ]]; then
if [[ -n "$recipient" && ( -n "$alwaysmail" || ( -n "$lowmail" && ( -n "$LIMITEXCEEDED" || -n "$TIMEEXCEEDED" ) ) ) ]]; then
STAGE='sending e-mail'
(
echo "To: $recipient"
Expand Down
2 changes: 2 additions & 0 deletions speakoutinforc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ recipient=$USER@localhost
# Lower limit (in dollars) below which a warning e-mail is generated; defaults to 0
# lowmail must be set to yes for an e-mail to actually be sent.
warnlimit=5
# Start warning this number of days before expiry
expirydays=7
# Send an e-mail when the balance goes below warnlimit
lowmail=yes
# Set to yes to always send an e-mail, regardless of warnlimit, empty to send
Expand Down

0 comments on commit d879f6f

Please sign in to comment.