sarmic/bml-tg-notify/bml-tg-notify.sh

54 lines
1.7 KiB
Bash
Raw Normal View History

2021-05-12 06:07:11 +05:00
#!/bin/bash
2021-05-12 06:53:43 +05:00
source .env
2021-05-12 07:08:31 +05:00
mkdir -p ~/.cache/bml-cli/
2021-05-12 06:07:11 +05:00
TG_BOTAPI='https://api.telegram.org/bot'
BML_URL='https://www.bankofmaldives.com.mv/internetbanking/api'
COOKIE=~/.cache/bml-cli/cookie
2021-05-12 22:20:52 +05:00
2021-05-12 07:24:32 +05:00
while true; do
2021-05-12 06:35:36 +05:00
LOGIN=$(curl -s -c $COOKIE $BML_URL/login --data-raw username=$BML_USERNAME --data-raw password=${BML_PASSWORD} | jq -r .code)
2021-05-12 22:20:52 +05:00
2021-05-12 06:07:11 +05:00
if [ "$LOGIN" = "0" ]
2021-05-12 20:34:27 +05:00
then
PROFILE=$(curl -s -b $COOKIE $BML_URL/profile | jq -r '.payload | .profile | .[] | .profile' | head -n 1)
curl -s -b $COOKIE $BML_URL/profile --data-raw profile=$PROFILE > /dev/null
2021-05-12 06:07:11 +05:00
else
echo Something went wrong
exit
fi
2021-05-12 22:20:52 +05:00
2021-05-12 06:07:11 +05:00
CHECKDIFF1=$(echo $HISTORY | wc -c)
HISTORY=$(curl -s -b $COOKIE $BML_URL/account/$BML_ACCOUNTID/history/today | jq -r '.payload | .history | .[]')
2021-05-12 06:25:45 +05:00
CHECKDIFF2=$(echo $HISTORY | wc -c)
2021-05-12 20:45:36 +05:00
SLEEP=$(cat delay)
sleep $SLEEP
2021-05-12 22:20:52 +05:00
if [ "$CHECKDIFF1" != "$CHECKDIFF2" ]
2021-05-12 20:34:27 +05:00
then
2021-05-12 22:20:52 +05:00
DESCRIPTION=$(echo $HISTORY | jq -r .description | head -n1)
AMOUNT=$(echo $HISTORY | jq -r .amount | head -n1)
if [ "$DESCRIPTION" = "Transfer Credit" ]
then
FROMTO=From
ENTITY=$(echo $HISTORY | jq -r .narrative3 | head -n1)
elif [ "$DESCRIPTION" = "Transfer Debit" ]
then
FROMTO=To
ENTITY=$(echo $HISTORY | jq -r .narrative3 | head -n1)
elif [ "$DESCRIPTION" = "Salary" ]
then
ENTITY=$(echo $HISTORY | jq -r .narrative2 | head -n1)
fi
echo $DESCRIPTION
echo $FROMTO: $ENTITY
echo $CURRENCY: $AMOUNT
DESCRIPTION=`echo $DESCRIPTION | sed "s/ /%20/g"`
ENTITY=`echo $ENTITY | sed "s/ /%20/g"`
TGTEXT=$(echo $DESCRIPTION%0A$FROMTO:%20$ENTITY%0A$CURRENCY:%20$AMOUNT)
curl -s $TG_BOTAPI$TG_BOT_TOKEN/sendMessage?chat_id=$TG_CHATID'&'text=$TGTEXT > /dev/null
2021-05-12 22:23:19 +05:00
echo "Next Check in $SLEEP seconds"
2021-05-12 06:07:11 +05:00
else
2021-05-12 22:20:52 +05:00
echo "nothing new..checking again in $SLEEP seconds"
2021-05-12 06:07:11 +05:00
fi
done